Comparing Google Closure with UglifyJS
10 July 2011
So, I threw UglifyJS into the mix and instead of replacing the Closure compiler I added it so it runs alongside but I obviously only keep one of the outputs.
Here is the log output when I run it on my MacbookPro:
MAKING ./static/js/account.js UglifyJS took 0.0866 seconds to compress 3066 bytes into 1304 (42.5%) Closure took 1.2365 seconds to compress 3066 bytes into 1225 (40.0%) MAKING ./static/js/ext/jquery.cookie.js UglifyJS took 0.0843 seconds to compress 3655 bytes into 3009 (82.3%) Closure took 1.3472 seconds to compress 3655 bytes into 4086 (111.8%) MAKING ./static/js/ext/jquery.tipsy.js UglifyJS took 0.1029 seconds to compress 7527 bytes into 3581 (47.6%) Closure took 1.3062 seconds to compress 7527 bytes into 3425 (45.5%) MAKING ./static/js/maxlength_countdown.js UglifyJS took 0.082 seconds to compress 1502 bytes into 1033 (68.8%) Closure took 1.2159 seconds to compress 1502 bytes into 853 (56.8%) MAKING ./static/js/ext/socket.io-0.6.3.js UglifyJS took 0.299 seconds to compress 76870 bytes into 30787 (40.1%) Closure took 2.4817 seconds to compress 76870 bytes into 30628 (39.8%) MAKING ./static/js/scoreboard.js UglifyJS took 0.084 seconds to compress 2768 bytes into 1239 (44.8%) Closure took 1.2512 seconds to compress 2768 bytes into 1167 (42.2%) MAKING ./static/js/rumbler.js UglifyJS took 0.0872 seconds to compress 3087 bytes into 1384 (44.8%) Closure took 1.2587 seconds to compress 3087 bytes into 1235 (40.0%) MAKING ./static/js/ext/shortcut.js UglifyJS took 0.0987 seconds to compress 5796 bytes into 2537 (43.8%) Closure took 1.3231 seconds to compress 5796 bytes into 2410 (41.6%) MAKING ./static/js/play.js UglifyJS took 0.1483 seconds to compress 18473 bytes into 10592 (57.3%) Closure took 1.4497 seconds to compress 18473 bytes into 10703 (57.9%) MAKING ./static/js/playsound.js UglifyJS took 0.0824 seconds to compress 1205 bytes into 869 (72.1%) Closure took 1.2335 seconds to compress 1205 bytes into 873 (72.4%)
(Note here that for the file
./static/js/ext/jquery.cookie.js Closure failed and when it fails it leaves the code as is and prepends it with a copy about the error from the stdout. that's why it's greater than 100% on that file)
Here are the averages of those numbers:
AVERAGE TIME: (lower is better) * UglifyJS: 0.11554 seconds * Closure: 1.41037 seconds AVERAGE REDUCTION: (higher is better) * UglifyJS: 45.6% * Closure: 51.5%
(I'm skipping the file that Closure failed to minify)
The fact that Closure fails on one file is a real bummer. I'm not even using the advanced options here.
UglifyJS doesn't save as many bytes as Closure does. This is potentially important because after all, minification process happens only once per revision of the original file but might be served hundreds or millions of times.
Because I run my minifications on-the-fly it does matter to me that UglifyJS is 1220% faster.
I've just noticed that I'm relying on files that almost never change (e.g.
jquery.tipsy.js). I might as well create a
...min.js versions of them and add them to the repository.
Because of the convenience of UglifyJS being so much faster and that it doesn't choke on that jquery.cookie.js file I'm going switch to UglifyJS for the moment. The remaining bytes that I don't save become insignificant if you add the gzip effect and compared to images the bandwidth total is quite insignificant.