Closure-compiler has a custom pass specifically to process jQuery. This branch of jQuery has the necessary changes and annotations to fully work with Closure-compiler.
The easist method is to download the pre-built source.
You can also build your own version from source. Use the same directions as building the main jQuery source, but substitute cloning this repository instead of the main jQuery repository. You'll also need to checkout the closure-compiler-1.9 branch once you clone the repository. You need to clone my sizzle repository into the src folder and checkout the closure-compiler-1.9 branch of it too.
Make sure to use the --process_jquery_primitives flag of the compiler. It won't compile correctly without it.
Example compilation command:
java -jar compiler.jar
--compilation_level ADVANCED_OPTIMIZATIONS
--warning_level VERBOSE
--process_jquery_primitives
--js jquery.closure-compiler.js
--js myjqueryplugin.js
--output_wrapper "(function() {%output%})()"
- Closure-compiler doesn't handle aliases well so the $ shortcut has been removed.
- jQuery.Event and jQuery.Tween are constructors
- jQuery.Deferred and jQuery.Callbacks return anonymous types which adhere to the jQuery.deferred and jQuery.callbacks interfaces. Neither is a constructor. jQuery.deferred and jQuery.jqXHR implement the jQuery.promise interface. Ancillary type information can be found in https://github.com/ChadKillingsworth/jquery/blob/closure-compiler-1.9/src/closure-compiler.js
Most properties can and should be used unquoted (jQuery.myPropery as opposed to jQuery["myProperty"]) This build does support the experimental type-based optimizations which are enabled using the --use_types_for_optimization flag
Many of the deprecated methods have been removed and a future build will probably remove any I have missed. You shouldn't be using deprecated methods.
It's been a challenge modifying jQuery style code into a format that can be successfully processed by Closure-compiler. The public API methods all have type annotations, but the same type-casting requirements that come with using the official externs, apply here as well. Some dead code elimination does occur, but not as much as I had hoped. It will take some time to identify what blocks particular sections of code from being eliminated.
More information on how the compiler handles jQuery
If you encounter bugs (which is highly probable), you should NOT post them on the closure-compiler issue tracker or on the official jQuery issue tracker. Instead, post them to this GitHub repository