What is the YUI Compressor?
How does it work?
with, the YUI Compressor takes a defensive approach by not obfuscating any of the scopes containing the evil statement). The YUI Compressor is open-source, so don’t hesitate to look at the code to understand exactly how it works.
Where can I get it?
An archive containing both source and binary is available for download on this site.
How do I run it?
java -jar yuicompressor-1.0.jar [-h, --help] [--warn] [--nomunge] [--charset character-set] [-o outfile] infile
The following command line for example:
java -jar yuicompressor-1.0.jar myfile.js
will minify the file
myfile.js and output the file
myfile-min.js. For more information on how to use the YUI Compressor, please refer to the documentation included in the archive.
Has Yahoo!’s official position on obfuscation changed?
Douglas Crockford wrote an interesting article last year on minification vs. obfuscation. While that article still holds true, the YUI Compressor actually represents a 3rd way, in which code compaction does not carry the risk of introducing new bugs. The YUI Compressor is currently considered as a replacement for JSMin to compact the entire YUI library.
The YUI Compressor is still a fairly new tool, so your feedback is well appreciated. Don’t hesitate to drop me a line if you find a bug, or think an important feature is missing. I will make updates available on this site, so watch for posts related to the YUI Compressor on this blog. This software belongs to the community, so it’s up to the community to make it better!
- Do not hesitate to use the
--warnoption. The YUI Compressor will warn you if it finds anything that seems abnormal with your code, or that might reduce the level of compression.
- Keep as little of your code as possible in the global scope. This has 2 benefits:
- You’ll get a better level of compression since the YUI Compressor does not obfuscate global symbols (which would make it unsafe)
- You won’t pollute the global object (see this article)