A Web Developer's Diary

Minifying, Combining and Caching CSS and JS with Code Ingiter

6/29/2012

0 Comments

 
So you realised all these HTTP requests are taking up a lot of page load time? No worries! You'll be up to speed in no-time.

First download the improved version of the CI plugin Carabiner from github (or download zip), originally written by Tony Dewan and now maintained by Mike Funk. Copy the config and libraries folder into your CI installation by putting them in: application/third_party/carabiner/ and add the package to application/config/autoload.php by adjusting the auto loaded packages:
 $autoload['packages'] = array(APPPATH.'third_party/carabiner'); 
Make sure the application/third_party/carabiner/config/carabiner.php configuration file is set properly (e.g. make sure the cache path exists and is writeable) and you can test your first Minify/Combine/Cache experience using this example controller:
  
class TestCarabiner extends CI_Controller {
public function index() {
$this->load->library('carabiner');
$this->carabiner->css('file1.css');
$this->carabiner->css('file2.css');
$this->carabiner->js('file1.js');
$this->carabiner->js('file2.js');
$this->carabiner->display(); // output html which loads cached files
}
}
Besides using $this->carabiner->display() you can also use $this->carabiner->display_string() to get the HTML as a string instead of outputting it directly to the browser (e.g. so you can use it in a template). You can also call carabiner directly from a Code Igniter view using $this->carabiner->display(). Another useful function call is $this->carabiner->empty_cache('both', 'yesterday') which cleans up old cache files. Full documentation is available at this page.
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    Author

    Blog about random challenges of a web developer.

    Archives

    April 2015
    May 2013
    January 2013
    July 2012
    June 2012

    Categories

    All
    Aws
    Cdn
    Code Igniter
    Css
    H2database
    Jamp
    Java
    Javascript
    Magento
    Maven
    Mysql
    Opencl
    Php
    Play-framework
    Quercus
    Scala
    Ubuntu

    RSS Feed

Powered by Create your own unique website with customizable templates.