[OpenLayers-Dev] Closure Compiler support

christopher.schmidt at nokia.com christopher.schmidt at nokia.com
Thu Feb 24 19:11:58 EST 2011


I have just added support to OpenLayers to support the closure
compiler when building OpenLayers files. To take advantage of 
this support on trunk, you must first place a closure-compiler.jar
file in your tools directory. From the build/README.txt file:

 * closure
   This requires you to have a closure-compiler.jar in your
   tools directory. You can do this by fetching the compiler


   Then unzipping that file, and placing compiler.jar into tools
   and renaming it closure-compiler.jar.

(This will also require you to have support for running java at the
command line.)

To use this compressor once you have downloaded it, you can run the
following build command:

  python build.py -c closure full

For smaller builds (not full builds -- they're too big), you can use
the closure webservice by instead specifying closure_ws:

  python build.py -c closure_ws lite

The output will be the same, but your code will be posted to the closure
web service as part of the build. (The size limit is 1MB.)

Closure is an advanced compiler provided by Google; it is Open Source 
(under the Apache2 license) and offers significant savings over our
default jsmin compiler, lowering compressed build sizes by approximately
15%. The numbers:

Full Builds:

900504  OpenLayers-jsmin.js
719130  OpenLayers-closure.js (20% savings)

200584  OpenLayers-jsmin.js.gz
172663  OpenLayers-closure.js.gz (14% savings)

Lite Builds:

123091  OpenLayers-lite-jsmin.js 
 96678  OpenLayers-lite-closure.js (21% savings)

 30977  OpenLayers-lite-jsmin.js.gz
 26347  OpenLayers-lite-closure.js.gz (15% savings)

Using the closure compiler, all OpenLayers tests continue to pass,
and the examples that I have tested appear to continue to work. The live
examples at http://openlayers.org/dev/examples/ are now using 
a closure-based build as well, so if you have any problems with these
examples, please report them to the mailing list.

As always, using minimal build profiles and gzipping javascript before
delivering it is the best way to minimize Javascript download size.


-- Chris

More information about the Dev mailing list