Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

John Cox's Blog:
Compressing Javascript with PHP
Jun 19, 2005 @ 22:47:22

In one of his latest posts on his weblog, John Cox talks about how you can compress javascript using a simple GZIP trick.

I have been learning the Rico Javascript Library this weekend. My only complaint about using any Javascript library is the weight that it adds to my output. With that in mind have made a very quick test for compressing Javascript with GZIP via PHP. This method is inspired by Fifty Four Eleven's post on compressing CSS with GZIP. In fact, I am using the same script, but changing the header type to text/javascript vice text/css. Read on for code examples.

He mentions testing it with Firefox and IE 6 with no problems, but hasn't tried it outside of that. Seems like if you have enough of a controlled environment, and can get away with using a trick like this, a reduction (in his example) from 80k to 16k just might be worh it...

tagged:

Link:


Trending Topics: