Welcome Guest, Not a member yet? Register   Sign In
Asset Manager Library Update

Hi Guys,

Just wanted to post an update to my asset manager library... cleaned up some code and added to the Readme file.



I'll be adding minify and combine options soon.


I just want to share something with you, because it helps with caching, and making sure new versions of files are used when necessary. I use the following code to add a version to my css files:

PHP Code:
// Add any additional stylesheets
if( isset( $style_sheets ) )
    foreach$style_sheets as $href => $media )
        ifstrpos'http'$href ) === )
            echo '<link href="' $href '" media="' $media '" rel="stylesheet" />' "\n";
            $css_lastmod is_fileFCPATH $href 
                filemtimeFCPATH $href )
            echo '<link href="' $href '?v=' $css_lastmod '" media="' $media '" rel="stylesheet" />' "\n";    

I have a different one for js files, but the concept is the same.

I have a small addition to @skunkbad. I use a different file naming method for even better caching on the client side. I use the format "styles.1456341663.css" instead of "styles.css?v=1456341663". I do this because appending a parameter to a url result in a miss on a caching proxy a visitor might use.

For more details about this subject:

You can use .htaccess to reroute styles.1456341663.css back to styles.css so you can just override the same styles.css file like you are doing now and benefit from more caching capabilities on the client side (and still have the ability to burst the cache).

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L]

Awesome and valuable changes.

Guys please feel free to submit a PR for these changes... I'll add em immediately. We can turn this into something very useful for the CI community.


Theme © iAndrew 2016 - Forum software by © MyBB