We just released a small module (Speedy - done in a few hours thanks to Webber and it's flexibility) which is supposed to make your pages way faster by reducing the number of HTTP requests a browser has to satisfy when loading a page.
Basically, the module will capture the main content being sent to the browser by Webber and modify it by combining all the javascript and css files into one file, all the css files into one file as well and send those 2 to the browser instead of the original ones. For example, if you have 6 js files loaded in your page and 3 stylesheets, speedy will capture them before the page being rendered in the browser and create only 2 files. This way you cut down the number of requests from 9 to 2. It also adds far future expires headers to instruct the browser to cache them for a better and faster browsing experience.
The module is very easy to install. At the activation point, it gives you the option (also editable from the module admin interface after activating) to specify how exactly should speedy change your content. You can chose to minify and/or gzip your page or javascript and css files and you can also specify if the files should contain far future expires headers which will make them cacheable by the browser which is a very good thing since it really makes your website fast.
In my humble opinion, there's always room for web page optimisation or performance tuning. The advantage is huge since you and your team can keep and maintain a very well structured set of files and not worry about numbers since speedy will reduce them without modifying any of them. Speedy creates it's own file stored in a local temp folder and uses those files instead of the original ones.
For those of you with a codeigniter background I will continue this post with a small tutorial on implementing PHPspeedy (what our module uses) into your websites without having to use this module or even Webber at all.
I usually keep a folder inside my codeigniter projects named "scripts" where I place anything that can't be called a library or helper. Assuming you have already downloaded PHPSpeedy and placed it in your folder of choice we will continue by creating a hook (that's right, enable them from your config.php file) which will add a "display_override" action in order to capture the content before it's being sent to the browser since PHPspeedy needs to manipulate it and make it's own version.
For Webber, we modified the 'Hooks' library to permit us to load hooks directly from a given module but, for this tutorial to achieve it's goal, you will have to create a new PHP file (name it whatever you like) and place it inside 'system/application/hooks' folder. This will be the hook file to capture the content and run speedy. As per instructions, the new file must contain a class and at least one method to be called by the hooks library that Codeigniter triggers at every load.
class Speedy {
function optimize ()
{
$this->CI =& get_instance ();
// catch the output and store it inside a variable
$output = $this->CI->output->get_output ();
// load PHPspeedy
require ( '/path/to/speedy/php_speedy.php' );
// send the new content
$compressor->finish ( $output );
}
}
With the hook saved and ready to function we only need to save our new hook to the hooks.php config file (system/application/config) and "the THANG" should be running:
$hook['display_override'] = array ( 'class' => 'Speedy', // the name of the PHP class 'function' => 'optimize', // the function/method to execute 'filename' => 'speedy.php', // or however you used to name it :) 'filepath' => 'hooks' // the path to your hook file );
