Saturday, December 6, 2008

Combine CSS/JS Files in One Call [Combine Solution]

After Reading lots of articles, regarding optimisation of page renders, found something interesting script, easy to implement combine cc/js calls in one go.

The idea of concatenating JavaScript and CSS has been implemented on other platforms too.
Thanks to Rakaz’s PHP Combine Solution.
Lets Take Example:

http://www.domain.com/javascript/prototype.js
http://www.domain.com/javascript/builder.js
http://www.domain.com/javascript/effects.js
http://www.domain.com/javascript/dragdrop.js
http://www.domain.com/javascript/slider.js
You can combine all these files to a single file by simply changing the URL to:

http://www.domain.com/javascript/prototype.js,builder.js,effects.js,dragdrop.js,slider.js

Download Combine Php Script.
Re-Write Apache Rule like this:

RewriteEngine On
RewriteBase /
RewriteRule ^css/(.*\.css) /combine.php?type=css&files=$1
RewriteRule ^javascript/(.*\.js) /combine.php?type=javascript&files=$1

This might help in optimising the pages.
I will try to setup one example, to give you usefulness of this.