Hacker News new | past | comments | ask | show | jobs | submit login
Compression of JavaScript programs (bitsnbites.eu)
23 points by _DanielH on April 28, 2011 | hide | past | favorite | 6 comments



A document [1] by Ray Cromwell introduces an aid for JS compression, both theory and implementation [2]. The idea is to transform JS code before compression in a way that, while keeping JS semantics, makes is best possible candidate for the popular gzip deflate compression.

----

[1] http://timepedia.blogspot.com/2009/08/on-reducing-size-of-co...

[2] http://code.google.com/p/google-web-toolkit/source/detail?r=...


That's a really awesome article--I remember when I first read it that it was both really interesting, well written and useful knowledge.

I thoroughly recommend taking the time to read it.


cough your server could serve gzipped stream and the browser would transparently uncompress it.

Sure there are browsers that can't decompress these streams, but your webserver already knows when to send the full (but minified) JS instead. Its all handled automatically.


He mentions "small source size" competitions as one of the reasons for doing this and they all count the size of the raw js file, not the size of the gzipped file as sent by the server.


"Minifying" will still produce generally lower bandwidth use with automatic stream compression, and you get a significant benefit even for users who have broken browsers (or are stuck behind broken proxies) that don't support stream compression.


This is a great process to maximize your JS compression. However, it's important to keep in mind the application. From the jQuery dl page (yes, they use a different compression method):

"The packed versions require non-trivial client-side processing time to uncompress (unpack) the code whereas the minified versions do not."




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: