Part of the EllisLab Network
   
 
Asset Joiner/Compressor Library
Posted: 20 March 2008 07:58 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  35
Joined  09-08-2007

Hello CodeIgniter Community,

this will be my first submission for CI - don’t expect too much smile

This Library gives you the chance to add assets to your project and output them in a joined (optionally compressed) file. This works for css (csstidy 1.3) and jsmin (jsmin-1.1.1).

Get the Library here:
v0.1: AssetLib

Here is a little example:

Controller:

$this->load->library('assetlib');
        
        
$config['enable_csstidy'] = TRUE;
        
$config['enable_jsmin'] = TRUE;
        
$config['csstidy_config'] = array(
                
'remove_bslash' => TRUE,
                
'compress_colors' => TRUE,
                
'compress_font-weight' => TRUE,
                
'lowercase_s' => FALSE,
                
'optimise_shorthands' => 1,
                
'remove_last_,' => TRUE,
                
'case_properties' => 1,
                
'sort_properties' => FALSE,
                
'sort_selectors' => FALSE,
                
'merge_selectors' => 2,
                
'discard_invalid_properties' => FALSE,
                
'css_level' => 'CSS2.1',
                
'preserve_css' => FALSE,
                
'timestamp' => FALSE,
        );
        
$config['csstidy_template'] = "high_compression";
        
        
$this->assetlib->initialize($config);
        
        
$this->assetlib->add("/style/default.css" );
        
$this->assetlib->add("/style/default_cs.css" );
        
$this->assetlib->add("/assets/astrumnex.js" );

In the $config[‘csstidy_config] variable you can use any config variable from csstidy to compress the code in your way.

View:

<?=$this->assetlib->output('all'); ?>

or

<?=$this->assetlib->output('css'); ?>

or

<?=$this->assetlib->output('js'); ?>

results:

<link rel="stylesheet" href="/assets/base.css" type="text/css" media="screen" />

Installation:
Step #1: You need to add some lines to your config.php file:

/*
|--------------------------------------------------------------------------
| Asset storage
|--------------------------------------------------------------------------
|
| The path to where to storage the joined assets. The assetlib will store
| as "base.css" and "base.js". (relative from CI index.php)
|
| asset_storage = "/assets" (as example)
|
*/
$config['asset_storage']    = "/assets/";
$config['asset_cache']    = TRUE;
$config['asset_expiration']    = 7200;

/*
|--------------------------------------------------------------------------
| CSSTidy Config
|--------------------------------------------------------------------------
|
| The path from your site's root in which the csstidy folder is. Note
| this is from the site's root, not the file system root. Also note the
| required slashes at start and finish.
|
| csstidy_basepath = "/system/plugins/csstidy" (as example)
|
*/
$config['csstidy_basepath']    = "/plugins/csstidy/";

/*
|--------------------------------------------------------------------------
| JSmin Config
|--------------------------------------------------------------------------
|
| Enter the path to your jsmin.php file. (relative from BASEPATH)
|
| jsmin = "/system/plugins/jsmin1.1.1.php" (as example)
|
*/
$config['jsmin']    = "/plugins/jsmin-1.1.1.php";

Step #2:
Paste “assetlib.php” in your /system/application/libraries folder.

Step #3 (optionally):
Download csstidy
and put the contents of the package into your /system/plugins folder (or wherever you’ve set it in your config file)

Download jsmin
and put the jsmin-1.1.1.php into your /system/plugins folder (or wherever you’ve set it in your config file)

Please give me some feedback smile

 Signature 

http://www.mindpress.de

Profile
 
 
Posted: 20 March 2008 08:17 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
Joined  02-13-2008

Thanks. I’ll try to use it instead of apache filtering approach.

Profile
 
 
Posted: 08 May 2008 05:14 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  65
Joined  03-17-2008

You might also want to check out AssetLibPro, which is based on AssetLib:
http://codeigniter.com/forums/viewthread/78931/

Once again, thanks a lot to Andre (a.k.a Daeli) for allowing to use source code of AssetLib. cool smirk

 Signature 

AssetLibPro - An advanced CI Asset Library
Improving CI’s native Caching

Profile
 
 
Posted: 22 May 2008 08:15 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  162
Joined  02-14-2007

Hmmm both of these look pretty good.

 Signature 

Trying to do it right the first time! whoops guess that didn’t work out so well…

Profile
 
 
Posted: 22 May 2008 11:27 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  105
Joined  07-14-2007

What’s the difference and which one is the most light weight

 Signature 

Hell Horror - CodeIgniter Community for Horror Fans

Profile
 
 
Posted: 22 May 2008 06:49 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  65
Joined  03-17-2008
RaZoR LeGaCy - 22 May 2008 11:27 AM

What’s the difference and which one is the most light weight

The standard AssetLib is definitely the most lightweight.
But to my mind the really little(!) weight of the pro version is more than worth it.

What’s so great about it is, that you install it once and never even have to think about it.
Changes in your CSS/Js files are automatically detected and the caches updated.
You don’t even have to flush your caches when editing your CSS code for testing.

Here are the major advantages I broupght to AssetLib Pro’s:
1. Fixes relative url() paths in your css files to ensure their validity.
2. Re-creates compressed files automatically once a source file was changed making sure that your cached files are always up-to-date.
3. Sets HTTP headers for far-future caching expiration for forced browser caching.
4. Supports branching for the use of multiple CSS selections (like “screen” or “print”).
5. Allows you to use multiple sets of css/js files per CI application for minimized performace overhead
6. Supports GZip compression of cached files to take bandwidth optimization a step further.

I just hope that this doesn’t look like I’m trying to hijack this thread red face
I have to give credits to Daeli’s work. My version is based on his implementation of TidyCSS and JSMin
as I was just too lazy to build it all from scratch. I re-wrote about 60% of the code though, to make it work the way I wanted it to.

 Signature 

AssetLibPro - An advanced CI Asset Library
Improving CI’s native Caching

Profile
 
 
Posted: 02 June 2008 11:20 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Avatar
Rank
Total Posts:  65
Joined  03-17-2008

This issue should apply to AssetLib, too: http://codeigniter.com/forums/viewthread/78931/P10/#408263
(missing error message for missing or unreadable files)

 Signature 

AssetLibPro - An advanced CI Asset Library
Improving CI’s native Caching

Profile
 
 
Posted: 05 November 2008 08:12 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  13
Joined  11-05-2008

I am newbie when it comes to AssetLib pro. I followed the Wiki Section but that didn’t work. Do you know how can I use this library. I did exactly like the instruction says but it prints nothing in Views.

Where I need to put JS and CSS. This is what I did

$this->load->library('assetlibpro');

$this->config->load('assetlibpro');

$this->assetlibpro->add_css('css/index.css');

Please help me out.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 119125 Total Logged-in Users: 60
Total Topics: 125465 Total Anonymous Users: 4
Total Replies: 660486 Total Guests: 465
Total Posts: 785951    
Members ( View Memberlist )
Newest Members:  kracha95tanjahagresifBlunklenarezecomodlostunlockedmarcusbrody10ghadbanRachelRiley