jQuery compiled with Google Closure Compiler
Has anyone compiled jQuery against Google's newly-released Closure compiler?
There has been reported huge savings in code size. I'm curious what the benefit is if jQuery was compiled with it.
Solution 1:
John Resig reported a bug on recursive functions when he attempted to compile a nightly of jQuery 1.4, so there are a few kinks to be worked out. I wouldn't use a jQuery compiled with Closure Compiler without making sure it passes the jQuery testbed.
http://code.google.com/p/closure-compiler/issues/detail?id=1&can=1#c2
Solution 2:
I tried with jQuery jQuery 1.3.2
jQuery-1.3.2.min.js 57254 Bytes
jQuery closure compiler 49730 Bytes
-----------------------------------
Reduced by 7524 Bytes
Saved 13.31% off the original size
Saved 10.87% off the gzipped size
Gain of ~7KB
But it also reports 15 Warnings and I didn't test if it still works
Solution 3:
The closure compiler eliminates any code that you don't actually use. The typical web page will only use a small fraction of jQuery functions, so the most benefit will come from compiling your code together with the full version of jQuery.
Solution 4:
With ADVANCED_OPTIMIZATIONS turned off:
- jquery-1.3.2.min.js: 57254 bytes
- jquery-1.3.2.closure.js 55346 bytes (-3.4%)
- jquery-1.3.2.min.js.gz: 19680 bytes
- jquery-1.3.2.closure.js.gz: 18666 bytes (-5.2%)
With ADVANCED_OPTIMIZATIONS turned on: it doesn't work unmodified. With ADVANCED_OPTIMIZATIONS turned on and everything I can find to export exported... it still doesn't quite work, and the code is already up to 53466 bytes again (and 18785 gzipped, which is more than the gzipped closured code without ADVANCED_OPTIMIZATIONS) so it doesn't look like a winning proposition.