26th
JUN

Gzip and cache CSS and Javascript files dynamically for faster page loads

Posted by Lee under CodeIgniter, Programming

David came across a handy script the other day that we have decided to implement into our CMS that dynamically Gzips and caches CSS and JS files - all without the need to have to change any of your HTML source destinations for those files. As a part of the implementation I also setup the script to work within the standard CodeIgniter cache setup and file structure.

Below is how I have it setup at the moment in CodeIgniter and yes its not a controller as such but pretty much acts like one and keeps all application code in the one spot hence the location/setup.

(If you are like me and have application folder set outside of the system folder then remove all instances of ‘system/’ and set the baseDir with one less ‘../’)

1. Extract the ‘smartoptimizer’ folder into ‘system/application/controllers/smartoptimizer’

2. Add the smartoptimizer htaccess details to the bottom of my htaccess details and replace all instances of ‘smartoptimizer/’ with ‘system/application/controllers/smartoptimizer/’

3. Edit ‘system/application/controllers/smartoptimizer/config.php’ and change the following settings as below:

$settings['baseDir'] = '../../../';
$settings['cacheDir'] to '../../cache/';

Leave a Reply

(required)
(will not be published) (required)

The Lab is the web development blog for PX Webdesign that covers many subjects from PHP, CSS, jQuery, CodeIgniter, Design and XHTML / HTML