javascript: Which is the powerful javascript compressor

533 Views Asked by At

Which is the powerful JavaScript compressor than

http://www.bananascript.com/

because bananascript compress mootools uncompressed library(138KB) to 40KB. Which is the best result as compared to google JS Compressor, YUI Compressor, etc. Are there any pitfalls or cross browser problems I should be knowing of. So which one should i go for if i want to compress mootools uncompressed library. That way i can determine what to use to compress my other my custom JS files?

3

There are 3 best solutions below

0
On BEST ANSWER

Besides the raw size of the generated script, another thing that you must keep in mind is the performance required to executed that script. If the compression is done in a way that it requires the browser to first decompress or regenerate the original code then you are creating a performance hit so maybe choosing anyone of the other compressors would have been a better choice, specially as the files are sent once and cached at the browser, but the decompression must be done everytime the page is loaded.

0
On

I would recommend YUI Compressor. It is also used for to the official compressed version and pretty efficient. It is Java based and I use it during deployment but also on-demand (which needs caching since it is not very fast).

Download is here: http://developer.yahoo.com/yui/compressor/ Test it here: http://yui.2clics.net/

bananascript uses various String methods like split, replace to build the script and the worst you see in the end of the script: eval. This is the reason why even Dean Edwards packer is rarely used these days, eval adds a lot of computing overhead on each load and makes the browser window feel sluggish on each load. (More here: http://dean.edwards.name/weblog/2007/08/js-compression/)

You can give Closure Compiler from Google a try, but it requires you to optimize your code according to their guidelines for warning free compilation.

To summarize the best practices:

  1. Use a non-eval based compressor like YUI.
  2. Serve your scripts gzipped
  3. Compress all your scripts and dependencies in one file (not during development) or dependency injection (large scale applications) like Aaron Newtons Dependency Loader or require.js

0
On

As casablanca mentioned in his comment, they're all going to yield similar results, so you should prefer the one that you're most comfortable with.

Something else to consider when choosing a compression library is how will it might integrate with your build/release process.

Also, consider that most web servers can be configured to apply gzip (or similar) compression to the end-result file -- making the real number of bits sent across the wire even smaller.