Archive for May, 2011

Tiny, fast javascript with Google Closure-Compiler

I’ve just spent a few hours trying to clean up the javascript on a project that’s about to launch, and I’m really impressed with Google’s Closure-compiler, it’s available online, as a Rest API or as a java app. I’ve been running it on my machine, with a shell script to batch the compilation of .js files.

It not a ‘real’ compiler, it doesn’t produce machine code, but it not only shortens your code, such as variable names etc, it also optimises it, to make it more efficient.

//before closure compiler
var settings = { maxZoom: 6, gridSize: 65, styles: clusterStyles };
if( !!markerClusterer ) markerClusterer = null;
markerClusterer = new MarkerClusterer( map, markers, settings );
// after
j&&(j=null);j=new MarkerClusterer(map, markers, { maxZoom: 6, gridSize: 65, styles: clusterStyles } );

Read more…