Best way to GZip Javascript and CSS files

catonthecouchproductions
catonthecouchproductions used Ask the Experts™
on
Hey,

I have been reading some articles on Gzipping and I am trying to find the best way to gzip all of my javascript and css files. I came across some techniques with PHP and placing that at the top of your CSS, but not sure if there are any other practices.

Thanks,
Ryan
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
Commented:
I would prefer to do it externally from the PHP files (or any other files for that matter).

Apache and IIS both support compression at the web server level, so you don't really have to do any work in your application code. It does affect performance just a bit but may be worth it for bandwidth consumption.

Some articles

Apache
http://schroepl.net/projekte/mod_gzip/
http://nadeausoftware.com/node/33
http://www.innerjoin.org/apache-compression/howto.html

IIS
http://support.microsoft.com/kb/322603
http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/iis/5bce429d-c4a7-4f9e-a619-5972497b932a.mspx
Thank you, I am on a GoDaddy server and they suppose GZIP, but as you know you arent allowed to edit server configuration, unless it is code in the .htaccess.

Still confused on a best way to GZIP Javascript and CSS. So you are saying go the PHP route?
Top Expert 2009

Commented:
>>I would prefer to do it externally from the PHP files

My wording was poor. I meant to do the compression separately from PHP or any other application page. The web server is well adapted to do such compression so there is no reason to do it in PHP, unless of course your GoDaddy guys won't flip the config switch for you.

Its possible that it can be done from .htaccess, if you look at the article: http://www.innerjoin.org/apache-compression/howto.html then you will see option A is doable via .htaccess

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial