Best JavaScript compressor [closed]

What is the the best JavaScript compressor available? I’m looking for a tool that:

  • is easy to use
  • has a high compression rate
  • Produce reliable end results (doesn’t mess up the code)


I recently released UglifyJS, a JavaScript compressor which is written in JavaScript (runs on the NodeJS Node.js platform, but it can be easily modified to run on any JavaScript engine, since it doesn’t need any Node.js internals). It’s a lot faster than both YUI Compressor and Google Closure, it compresses better than YUI on all scripts I tested it on, and it’s safer than Closure (knows to deal with “eval” or “with”).

Other than whitespace removal, UglifyJS also does the following:

  • changes local variable names (usually to single characters)
  • joins consecutive var declarations
  • avoids inserting any unneeded brackets, parens and semicolons
  • optimizes IFs (removes “else” when it detects that it’s not needed, transforms IFs into the &&, || or ?/: operators when possible, etc.).
  • transforms foo["bar"] into where possible
  • removes quotes from keys in object literals, where possible
  • resolves simple expressions when this leads to smaller code (1+3*4 ==> 13)

PS: Oh, it can “beautify” as well. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *