11
June
12:31

JavaScript Compression

 
Tags:
Author: elPas0

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

4 Responses to “JavaScript Compression”

Scott
wroteScott

You should check out http://www.bananascript.com. 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.

izmir evden eve
wroteizmir evden eve

Thank you for sharing…

Scott
wroteScott

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.

Leave a Comment

* Required

E-mail will not be published