Best way to GZip Javascript and CSS files

catonthecouchproductions used Ask the Experts™

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.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009
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


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

>>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: 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