Closure Compiler is a JavaScript optimizing compiler.

http://code.google.com/p/closure-compiler/

 http://stackoverflow.com/questions/28932/best-javascript-compressor

Google released Closure Compiler which seems to be generating the smallest files so far as seen hereand here

Previous to that the various options were as follow

Basically Packer does a better job at initial compression , but if you are going to gzip the files before sending on the wire (which you should be doing) YUI Compressor gets the smallest final size.

The tests were done on jQuery code btw.

  • Original jQuery library 62,885 bytes , 19,758 bytes after gzip
  • jQuery minified with JSMin 36,391 bytes , 11,541 bytes after gzip
  • jQuery minified with Packer 21,557 bytes , 11,119 bytes after gzip
  • jQuery minified with the YUI Compressor 31,822 bytes , 10,818 bytes after gzip

@daniel james mentions in the comment compressorrater which shows Packer leading the chart in best compression, so I guess ymmv

link|improve this answer
 
 
Packer has an option to 'base62 encode' off - and for jQuery it compresses smaller than yui after gzip. This is because jquery uses 'eval' and 'with' which prevents 'safe' compressors from doing certain compressions, but packer ignores them. Not safe in general but jQuery is tested for Packer. – Daniel James Sep 17 '08 at 7:19
 
Also, try compressorrater.thruhere.net if you don't believe me. – Daniel James Sep 17 '08 at 7:22
6  
Don't forget the downside to packer--decompression time. – Nosredna Jun 7 '09 at 15:57
1  
Wow, this tool is pretty awesome. *&^@#$!! Google, they provide so many things that it kind of makes me wary to use them, since they do nearly everything these days. They are taking over the world... – Jason Bunting Aug 24 '10 at 16:33
 
watch out, google closure can sometimes be the worst compressor (output even larger than original) - it converts non-ascii characters in strings to \uxxxx literals by default.. use e.g. --charset UTF-8 (if you're sure you let the browser know about it somehow) – mykhal Feb 15 at 9:35

Closure Compiler

Closure Compiler is a JavaScript optimizing compiler. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. It is used in many of Google's JavaScript apps, including Gmail, Google Web Search, Google Maps, and Google Docs.

Try it out!

It's easy to try the compiler through our web application at http://closure-compiler.appspot.com/

Get the Compiler

Download the compiler at http://closure-compiler.googlecode.com/files/compiler-latest.zip or using Maven.

The zip file contains a README with quick instructions to get you started.

User Documentation

You can read more about Closure Compiler at http://code.google.com/closure/compiler/.

We also have a few low-key wiki pages at http://code.google.com/p/closure-compiler/w/list. Please suggest new ones if you see anything missing.

Developer Documentation

The Closure Compiler javadocs are available at http://closure-compiler.googlecode.com/svn/trunk/javadoc/index.html

You can browse the source at http://code.google.com/p/closure-compiler/source/browse/#svn/trunk

We accept patches :)

原文地址:https://www.cnblogs.com/wucg/p/2395278.html