Random Articles
-
Lenovo to replace defective ThinkPad batteries
Lenovo is offering to replace certain batteries... -
Ultrathin price drops may squeeze netbooks
The dominance of low-cost netbooks could be... -
Breevy Saves Text-Typing Time and Trouble
Breevy ($30, 30-day free trial) allows for... -
IBM using DNA, nanotechnology in next-gen chips
IBM Research said its scientists are using DNA... -
Tech vendors line up behind open gov't initiative
Ten companies, including several tech vendors,...
| Combining Javascript & CSS |
|
|
|
| Written by Joo Trans |
| Thursday, 13 August 2009 19:14 |
|
Take for example the following URLs: http://www.mysite.com/javascript/prototype.js You can combine all these files to a single file by simply changing the URL to: The script will intercept the attempt to retrieve something from the javascript directory and will notice that you want to fetch multiple files at once. It will then concatenate the requested files, compress it and send it as one to the browser. onfigurating this script is easy. First you need to download ands ave as combine.php file. By default this script look in the javascript and css directory in the root of your website, but if you are currently using different directories you can change these values at the top of the combine.php script. Upload the combine.php script to the root of your website. Secondly you need to create a cache directory that is writable by the web server. Again, by default this script will look for the cache directory in the root of the website, but you can change this in the combine.php script. Finally you need to add the following code into your .htaccess file. RewriteEngine On Note: if your preexisting .htaccess file already uses URL rewriting you do not need to add the first two lines. You can simply add the last two lines to the bottom of the .htaccess file. |



Compressing the files will decrease the size of the data that needs to be transferred, it does not solve the problem that the browser can only download a limited number of files at the same time. If you have many different files that need to be loaded the browser will not optimally use the bandwidth it has access to.