So you have your site running on the latest and greatest Java libraries, but your supporting CSS and JavaScript files are really starting to slow things down. You’re no JavaScript expert, so what do you do? Lucky for us some other people have already encountered this problem and have a great solution.
Make your pages load faster by combining and compressing javascript and css files
The site itself describes in great detail how the script works. It took some trial and error for me to get this thing working, so here are some tips:
- If your site’s root folder is in another directory on your server, make sure you create an .htaccess file in that directory. There may be an .htaccess file in your public_html folder already, but unless that is your site’s root folder, you should not change it. Once you edit and place this file in your site’s root, all CSS and Java files accessed in their respective directories will be redirected to the combine.php script.
- With the .htaccess file in mind, you need to place your combine.php file in the same directory, or edit your .htaccess file to point to combine.php.
- Combine.php will compact and compress your files and send them to a cache folder that you need to create, again, in your site’s root directory. This way the client’s browser will access the cached files and wont request new files needlessly.
- Once you have everything in place, you need to call your files in a way that the combine.php script recognizes. Here’s an example:
<script type="text/javascript" src="combine.php?type=javascript&files=prototype.js,effects.js,lightWindow.js"></script>
If everything went as planned, you will use less bandwidth, your site may load a bit faster and your visitors will never know.
Actually there are several on-the-fly compressing filters for JavaScript and CSS:
http://www.servletsuite.com/servlets/jstrimflt.htm
http://www.servletsuite.com/servlets/csstrimflt.htm
and the general tool:
http://www.servletsuite.com/servlets/trimflt.htm
JavaScript is not Java .
I’ve gotten into the bad habit of using them exchangeably. You make a good point.
[…] Combine and compress your CSS and Java […]
very interesting, but I don’t agree with you
Idetrorce
[…] Combine and compress your CSS and Java “So you have your site running on the latest and greatest Java libraries, but your supporting CSS and JavaScript files are really starting to slow things down. You’re no JavaScript expert, so what do you do? Lucky for us some other people have already encountered this problem and have a great solution.” […]
[…] Combine and compress your CSS and Java “So you have your site running on the latest and greatest Java libraries, but your supporting CSS and JavaScript files are really starting to slow things down. You’re no JavaScript expert, so what do you do? Lucky for us some other people have already encountered this problem and have a great solution.” […]