Part of the EllisLab Network
   
1 of 6
1
AssetLibPro - An advanced CI Asset Library
Posted: 08 May 2008 06:59 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  66
Joined  03-17-2008

AssetLibPro - An advanced CI Asset Library
http://code.google.com/p/assetlib-pro/

Release Date: Aug. 05th ‘08
Version: 1.0.5
Bug Fixes: Removed left over debugging statements.
Fixed all the stuff listed here
Improvements: Added support for “modules” for easy page theming.
(Thanks to a&w; for those suggestions and fixes!)
Changes: Paths now need to be relative to asset directory (see config file)
Link: Google Code Project

AssetLibPro uses code from AssetLib, (Thanks Andre!)
but does not have that much in common with AssetLib anymore.

In addition to AssetLib’s ‘jsmin’ and ‘csstidy’ functionality AssetLibPro brings you the following:

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.

Ps: Don’t forget to leave a comment if you like it (or don’t) wink

Profile
 
 
Posted: 08 May 2008 02:59 PM   [ Ignore ]   [ # 1 ]  
Grad Student
Rank
Total Posts:  45
Joined  09-08-2007

Hey TheLoops. Good luck with your project - it sounds very good smile

 Signature 

www.gamestack.net - a community around free gaming

Profile
 
 
Posted: 08 May 2008 03:31 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  747
Joined  01-13-2008

Your on me blog.

 Signature 

Yonti - I am Currently looking for a business partner, to create the best developer hosting out there. If your interested PM me.

Fluxity Lighting - My other company.


I’m a Proud Supporter and Sponser of Tomorrows Web.

Profile
 
 
Posted: 08 May 2008 03:35 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  2
Joined  05-08-2008

As web developers, we often run into problems while handling various assets such as images, scripts and css files. To make it easier to access and call such assets from within the Code Igniter framework, here is an implementation of the Asset Library, which we have been using at Wallwisher.com. Hope you find it useful.

Structure

In parallel to the Code Igniter system folder in your implementation, place a new folder called assets. Inside this folder, feel free to describe new assets such as images, scripts, styles and others necessary for your implementation. You need the following files to implement the library:
(get the code at www.wallwisher.com/blog)

Configuration File: to be placed in system/application/config/  (assets_config.php.txt)
Helper File: to be placed in system/application/helpers/ (assets_helper.php.txt)
Library File: to be placed in system/application/libraries/ (assets.php.txt)

Examples

Here are a few examples which might help you in understanding the usage of this library:

$new_image = ‘.’.asset_url(‘example.jpg’,‘images’);
$CI =& get_instance();  $new_css = $CI->assets->get_asset_from_name(‘css’,$name);

Profile
 
 
Posted: 08 May 2008 03:41 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  58
Joined  05-08-2008

Hi, there is an issue in the _fix_css_urls function: relative_path_to.
Also, when reading the code it seems to rebuild a non-relative path without the http:// part too.

Have disabled the function for now, and works nicely!

EDIT: add header(“Content-type: text/css”); to the CSS.php file

Profile
 
 
Posted: 08 May 2008 04:10 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  66
Joined  03-17-2008
Maxximus - 08 May 2008 07:41 PM

Hi, there is an issue in the _fix_css_urls function: relative_path_to.
Also, when reading the code it seems to rebuild a non-relative path without the http:// part too.

Have disabled the function for now, and works nicely!

The _fix_css_urls() function is only required if the css url() paths are set relative to the css file’s location.
If they are set relative to the web root (leading slash), then no re-linking is needed.

You are right, there was a bug in there. I uploaded a fixed v1.0.1: http://code.google.com/p/assetlib-pro/downloads/list

Profile
 
 
Posted: 08 May 2008 04:18 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Avatar
Rank
Total Posts:  66
Joined  03-17-2008

pranavpiyush, I’m not quite sure how your asset library is comparable to AssetLibPro?
Your library looks like a asset path repository, while AssetLibPro’ main purpose is bandwidth and performance optimization.

WackyWebs.net, thanks wink Good to see that you guys find it useful :-D

Profile
 
 
Posted: 08 May 2008 04:22 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  58
Joined  05-08-2008

Well to be honest I just read this part:

foreach ($matches['urls'as $old_url{
                    $old_url 
trim($old_url,'"\'');
                    if (strlen($old_url[1]) > 7 && strcasecmp(substr($old_url[1], 0, 7), '
http://') == 0) {
                        
$new_url $old_url;
                    
else {
                        $new_url 
dirname($css_path).'/'.$old_url;
                    
}
                    $urls[$old_url] 
relative_path_to(str_replace(dirname(FCPATH),'',trim($this->cache_dir_css)).'/'$new_url);
                

It seems to always do the relative_path_to function. Tried it with a relative_path_to function found on the net.

You were pretty quick with your reaction wink, just to make sure you see it: pls add header(“Content-type: text/css”); to the generated CSS when using .php extension.
EDIT: See it’s there but for some reason it was notgenerated in the file. I’ll look in to it…

Profile
 
 
Posted: 08 May 2008 04:31 PM   [ Ignore ]   [ # 8 ]  
Grad Student
Avatar
Rank
Total Posts:  66
Joined  03-17-2008
Maxximus - 08 May 2008 08:22 PM

Well to be honest I just read this part:

foreach ($matches['urls'as $old_url{
                    $old_url 
trim($old_url,'"\'');
                    if (strlen($old_url[1]) > 7 && strcasecmp(substr($old_url[1], 0, 7), '
http://') == 0) {
                        
$new_url $old_url;
                    
else {
                        $new_url 
dirname($css_path).'/'.$old_url;
                    
}
                    $urls[$old_url] 
relative_path_to(str_replace(dirname(FCPATH),'',trim($this->cache_dir_css)).'/'$new_url);
                

It seems to always do the relative_path_to function. Tried it with a relative_path_to function found on the net.

You were pretty quick with your reaction wink, just to make sure you see it: pls add header(“Content-type: text/css”); to the generated CSS when using .php extension.

The code checks the path for a leading “http://”. If it finds one, then the path is kept untouched. Else, it considers it relative and tries to re-link it.

Regarding the http header: The header refused to be added to the output due to a small bug. Check my first post for the updated v1.0.1 (at Google Code Project)

Profile
 
 
Posted: 08 May 2008 04:37 PM   [ Ignore ]   [ # 9 ]  
Grad Student
Avatar
Rank
Total Posts:  58
Joined  05-08-2008

Ok here’s the problem:

private function _http_headers($type ''$gzip_compress FALSE$far_future_expire TRUE{
        
if ($type === 'css')
            
$mime_type 'css';
        else if (
$type === 'js')
            
$mime_type 'javascript';
        else
            return 
FALSE;

        
$gzip_header "";

        if (
$gzip_compress{
            $gzip_header 
'<?php
// Gzip encode the contents of the output buffer.
function gzip_compress($output) {
$compressed_out = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$compressed_out .= substr(gzcompress($output, 2), 0, -4);
if (strlen($output) >= 1000) {
    header("Content-Encoding: gzip");
    return $compressed_out;
} else {
    return $output;
}
}
if (strstr($HTTP_SERVER_VARS["HTTP_ACCEPT_ENCODING"], "gzip"))
    ob_start("gzip_compress");
?>'
;
        
}
        
if ($far_future_expire{
            
//When will the file expire?
            
$offset 6000000 60 ;
            
$ExpStr "Expires: " .
            
gmdate("D, d M Y H:i:s",
            
time() + $offset)." GMT";

            
$far_future_expire .= '<?php
header("Content-type: text/'
.$mime_type .'; charset: UTF-8");
header("Cache-Control: must-revalidate");
header("'
.$ExpStr.'");
?>'
;
        
}
        
return $gzip_header;
    

The $far_future_expire will never be used, and should be $gzip_header. Personally I would prefer to have the Content-type header as one of the first, so it’s outputted also when there’s no far_future_expire.

Profile
 
 
Posted: 08 May 2008 04:50 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Avatar
Rank
Total Posts:  66
Joined  03-17-2008

Thanks Maxximus, it’s fixed now (v1.0.2).

<?php header("Content-type: text/css; charset: UTF-8"); ?> 

…is now sent no matter if you have far_future_expire or gzip_compress checked.
See first post for update link wink Thanks for the feedback guys! grin

Profile
 
 
   
1 of 6
1