EllisLab text mark
Advanced Search
     
Asset Linker 0.1.1
Posted: 29 December 2007 07:04 AM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-01
820 posts

Just something quick I noticed while using my Asset Linker. If you use caching, all paths to images used in stylesheets and such must be relative to the website public_html folder. Examples below.

This will not work due to the cache file being in a different directory to that of the original css file.

.picture { background#FFF url(../images/picture.gif); } 

It must be like this

.picture { background#FFF url(<?=base_url() . $this->config->item('assets_dir')?>/images/picture.gif); } 

You can use CI code inside the css files since they are executed before the cache is created, BUT you cannot use CI code if you don’t use cache. The whole address must be entered manually.

I know how to fix this issue so you don’t need to worry about the path of a file and will try and get a fix out later today. All that needs changing is where the cache file is stored.

 Signature 

Kaydoo - A day in the life of a developer
BackendPro Control Panel

 
Posted: 29 December 2007 05:03 PM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-01
820 posts

Write to fix the problem you need to change a few lines. I have also uploaded a new zip file with the fix and a few more changes to the code.

1. Delete the assets/cache folder.
2. Make sure the script can write to the following folders, (666 should be fine, 777 for sure)

assets
   
|- admin
      
|- css
      
|- js
   
|- public
      |- 
css
      
|- js
   
|- shared
      
|- css
      
|- js 

3. Replace the code on line 50

Replace this:
$file_path $this->CI->config->item('asset_cache_path') . $this->CI->config->item('asset_cache_prefix') . $main "." $type;

With this:
$file_path $this->CI->config->item($main '_assets') . $type "/" $this->CI->config->item('asset_cache_file') . "." $type

4. In the asset_linker config file change the following

Replace this (around line 81):
/*
 |--------------------------------------------------------------------------
 | Cache File Prefix
 |--------------------------------------------------------------------------
 | String to prepend to asset cache files.
 */
 
$config['asset_cache_prefix'"asset_cache_";

/*
 |--------------------------------------------------------------------------
 | Cache Path
 |--------------------------------------------------------------------------
 | Path to where cache files are stored. Should be relative to base_url()
 | and be able to be seen by public. IE don't set it to the CI cache folder.
 | String should end with a trailing slash
 */
 
$config['asset_cache_path'$config['assets_dir''cache/';

With this:
/*
 |--------------------------------------------------------------------------
 | Asset Cache File
 |--------------------------------------------------------------------------
 | File name you want the cache files to be called, please don't include extensions
 */
 
$config['asset_cache_file'"cache"

That will change the class so the cache files will be saved locally to the original style sheets so relative paths will still work.

As I said above I will upload a new version of the zip file with the changes in and a few extra ones I have discovered upon looking over it.

 Signature 

Kaydoo - A day in the life of a developer
BackendPro Control Panel

 
Posted: 01 January 2008 03:49 PM   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-01
820 posts

Sorry it has taken so long, hope everyone had a good new year. Those changes have been uploaded to the Wiki.

Asset Linker will now store all cache files in the relative dirs. IE the cache file for public css will be stored in assets/public/css.

I have also changed a few lines to add more file checks, hopefully to get rid of pointless file not found notices.

One other note, if people are thinking you can’t use this solution with media types you can just check out this page.

Todo List
- Work out best way to compress css & js files
- Look into caching assets which you loaded on the fly. (This may not be possible, but compression might be)

Get latest version here
Wiki Download Link

 Signature 

Kaydoo - A day in the life of a developer
BackendPro Control Panel

 
Posted: 10 March 2008 12:05 PM   [ # 14 ]   [ Rating: 0 ]
Joined: 2007-10-25
203 posts

Hi Adamp1—

I really like your idea but i’m a bit concerned with your presentation of performance difference. Foremost, I’m confused as to how a reduction in requests (by 7 HTTP requests) is accounting for about a 54% performance increase on initial download and 72% on re-browse.

On the pages that did not use asset linker, were you also compressing the individual files (ie 9 gzip files verus 2 gzip files) or were these uncompressed (9 uncompressed files versus 2 compressed files)? I can only really justify this performance difference if you used uncompressed files versus compressed files (since the HTTP requests only account for about 200ms difference in most cases).

My other concern is browsing between pages ... often times people may add or remove css or js files based on the page. It seems in these cases it should *increase* time to view for these pages, but your numbers don’t reflect this.

Could you possibly shed some light on this?

Thanks!

 
Posted: 10 March 2008 12:11 PM   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-01
820 posts

Yes sorry, basically it was all done uncompressed. So no gzip. For the pages when you want extra files these are not compressed. The case above does not include files loaded for just that page. Since this is on a page to page basis there isn’t much my script can do to help on that.

Basically the library is solely to make including css/js easyier, but also to speed up loading css/js which is needed throughout the site.

 Signature 

Kaydoo - A day in the life of a developer
BackendPro Control Panel

 
Posted: 10 June 2009 04:21 AM   [ # 16 ]   [ Rating: 0 ]
Joined: 2009-06-09
1 posts

Hello adamp1, i just joined this community and have been going over alot of the posts and discovered your asset linker. Being brand new please forgive me if my question should be obvious but i don’t seem to see in your files or the wiki any note if the asset_linker library needs to be loaded in the controler. I’m going to assume that you would need to load it in the controler since it seems most others do. Please correct me if i am wrong.

 
Posted: 10 June 2009 05:22 AM   [ # 17 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-01
820 posts

Yes you need to load it before any use. So in the constructor would be best. Or create an abstract base_controller with the load method in which all your controllers implement.

 Signature 

Kaydoo - A day in the life of a developer
BackendPro Control Panel

 
Posted: 08 July 2009 11:34 AM   [ # 18 ]   [ Rating: 0 ]
Joined: 2007-03-19
57 posts

Hello adamp1,

I apriciate your input to the community. Especially since I’m in need of this kind of thing!
My problem though is how do you solve it when you need to link in a stylesheet for IE6 and 7?
Example:

<!--[if IE]><link rel="stylesheet" type="text/css" href="stupidIE.css" /><![endif]--> 

You really should implement a function for that, since it’s a common practice.

I’ll get back to you if I come up with anything useful.

Regards,
Lockzi

 
Posted: 08 July 2009 12:16 PM   [ # 19 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-01
820 posts

This library is no longer being supported. If you would like features like above but even more powerful (including Browser specific assets) please have a look at BackendPro (link in my sig).

I know BackendPro is an entire admin area, but 1 of its modules is an Asset library. It would be simple to just use this part on its own.

 Signature 

Kaydoo - A day in the life of a developer
BackendPro Control Panel

 
Posted: 14 August 2009 09:01 AM   [ # 20 ]   [ Rating: 0 ]
Joined: 2009-08-14
9 posts

When I enable caching, by setting the asset_cache_length to a value different from 0, no stylesheets or javascript files get loaded.
Does anyone have a idea why?
Where do I need to put the cache folder?

 
Posted: 14 August 2009 09:32 AM   [ # 21 ]   [ Rating: 0 ]
Joined: 2009-08-14
9 posts

I constantly get this message written in my cache.css file:

A PHP Error was encountered

Severity: Warning
Message:  asset_linker::include() [asset-linker.include]: URL file-access is disabled in the server configuration
Filename: libraries/asset_linker.php
Line Number: 253

</div><div solid #990000;padding-left:20px;margin:0 0 10px 0;”>

 
Posted: 14 August 2009 10:13 AM   [ # 22 ]   [ Rating: 0 ]
Joined: 2009-08-14
9 posts

nevermind. There was a problem with the path to my assets folder.
I just removed the base_url() function from the asset_linker library where it writes the cache

 
Posted: 14 August 2009 02:38 PM   [ # 23 ]   [ Rating: 0 ]
Avatar
Joined: 2009-01-21
109 posts
adamp1 - 08 July 2009 04:16 PM

This library is no longer being supported. If you would like features like above but even more powerful (including Browser specific assets) please have a look at BackendPro (link in my sig).

Carabiner is a JS/CSS asset management library with similar goals that is in active development, with a pretty robust feature set.  See my signature for the link.

 Signature 

Do you use CSS or JavaScript? Carabiner makes your life easier.  I promise.

CI-Disqus makes playing with the Disqus API a snap.