The best way is to not do this at all, since all modern browsers and servers handle Gzip encoding. Look at the numbers:
- cfform.js - 21k
- cfform-minified.js - 12k
- cfform.js.gz - 4.2k
- cfform-minified.js.gz - 2.2k
This is a fairly large JS file with a lot of extra spaces, but in the final equation you saved a whopping 2k !! Not only that, but also due to the caching of this savings - per visitor, not per page. Whoo-hoo, now it was worth the whole problem, right?
You would save 10 times more by trimming the pixel width from the top of your banner, and 99% of your users on a broadband network you saved them about 1 millisecond of download time. Break the streamers and champagne!
JS compression is even worse since you just hit your customers with the decompression burden on EVERY PAGE. And savings after gzip are just as unhappy.
Seriously. The added complexity and debugging is not worth it if you are targeting the mobile market (and even this assumes that the users are still on CDMA and not 3G) or have a billion hits per day. Otherwise, just donβt worry.
SpliFF
source share