JavaScript Compression


If you developing rich web applications, you start to think how to compress JavaScript to keep bandwidth and page load times as small as possible. I found 5 different tools to compress javascript files, which can be run using cron, or run on some event to automate work on production-server.

1. JSMin. Commonly used compressor, based on simple rules, ported on many languages, including JavaScript

2. JavaScript::Minifier. Separate perl module, compression ratio equal to JSMin

3.Dojo ShrinkSafe aka Rhino. JavaScript compressor that parses the JavaScript using the rhino library, included in Dojo. Run as jar-module.

4. Dean Edwards Packer. Well-known tools from far-famed Dean Edwards. Ported on some languages, including PHP4/5.

5. YUI. JavaScript minifier designed to be 100% safe and yield a high compression ratio. Run as jar-module.

From my own experience i can tell
– no sense to compress files less 1 kb
– packer shows best results ( just my own opinion )
– always check you functionality of your compressed files. You can try to verify your code with JSLint
– remember that you can gzip compressed files to get smaller file

Good article about gzipping js

Did you like it? Help us spread the word!

7 Responses to "JavaScript Compression"

  1. Scott says:

    You should check out That guy has the best packer out of all of them. You can combine his with Dean Edwards or YUI (or both!) to get even better results. I use YUI and then bananascript. My 184kb of Javascript + MooTools gets down to 56kb before being GZipped.

  2. Thank you for sharing…

  3. Scott says:

    For anyone who read my above comment…the BEST results I have gotten is to use YUI and then let Apache with mod_gzip or mod_deflate compress your file when it is served. Passing it through Dean Edwards or Bananascript before it gets compressed by Apache will actually be detrimental to the compression and therefore performance of your site.


    That service will actually run your javascript through a whole list of different algorithms and options, and sort the results for you based on size, speed of de-compression (ie, client-side performance), etc. Then, you can see for your script, which is the best.

    For what it’s worth, on all my scripts, I seem to see YUI + gzip to be the best.

    It doesn’t support bannanascript (yet?), but as this technique is very similar to Dean Edward’s packer, and that packer *is* on there, and packer is usually much worse in performance client-side, I imagine bannanascript may fare similarly.

  5. elPas0 says:

    yes, i also notice that yui + gzip give the best result

Do you have something to say?