Example of using Closure Compiler to attain an 85% improvement over
YUI Compressor when minifying Closure Library code
I felt that a number of blog posts that I read on the Web dramatically
some tests that demonstrate how dramatic the effects of using the
exists today, is not written in such a way that is compatible with the Compiler's
Advanced mode, but the code in the Closure Library is.
To learn how to update your code to work with Advanced mode, read the
Advanced Compilation and Externs
article on the Google Code web site.
These tests were run using the following software:
Here are the results:
Doing the math:
|Size in bytes||Filename|| |
| 34291 || awesomebar-advanced-no-debug.js
||Closure Compiler with ADVANCED_OPTIMIZATIONS enabled, along with some additional CompilerOptions.
| 37714 || awesomebar-advanced.js
||Closure Compiler with ADVANCED_OPTIMIZATIONS enabled.|
| 193986 || awesomebar-simple.js
||Closure Compiler with SIMPLE_OPTIMIZATIONS enabled.|
| 223693 || awesomebar-yui.js
| 261322 || awesomebar-whitespace-only.js
||Closure Compiler with WHITESPACE_ONLY enabled.|
| 809709 || awesomebar-concat.js
||All of awesomebar.js's dependencies concatenated together.
This file was used as the input to YUI compressor whereas the
Closure Compiler received each dependency as an individual input.|
(1 - (34291 / 223693)) * 100% = 84.67% Savings
The code is
publicly available on Google Code if you want to try running the tests yourself.
If nothing else, this should serve as an
example of how to use the
Compiler and calcdeps.py from an Ant build file, as well as an example of
how to extend CompilerRunner to enable additional optimizations.