ShrinkSafe via Ant
The development of Pulse 2.2 has seen a steady increase in the amount of JavaScript we are using to drive our web front end. To help maintain a snappy user experience, we have started to look at products / packages to reduce the size of our JavaScript. The first such package that I encountered was ShrinkSafe, a part of the Dojo Toolkit.
ShrinkSafe is packaged as a jar file, and with the js.jar (Rhino) on the classpath, can be run as follows:
To run this via ant, you could do something like:
<java jar="shrinksafe.jar" fork="true" output="outfile.js">
<arg value="infile.js"/>
<classpath>
<pathelement location="js.jar"/>
</classpath>
</java>
Whilst effective, this does become a little verbose when you need to apply it to multiple JavaScript files and does not support a dynamic set of files. Since the Pulse build uses ant and has a growing set of JavaScript files, I created an ant task to drive ShrinkSafe, the source of which is available via github.
So now we can run shrinksafe as follows:
<taskdef name="shrinksafe" classname="com.zutubi.ant.shrinksafe.ShrinksafeTask"/>
<shrinksafe outputDir="${out.dir}" sourceDir="${src.dir}">
<include name="**/*.js"/>
</shrinksafe>
We can also append a suffix to the processed files for when we version them.
This entry was posted on Tuesday, May 25th, 2010 at 3:50 pm and is filed under JavaScript. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.











June 3rd, 2010 at 6:13 pm
a little madness » Blog Archive » JavaScript Compressor Comparison says:[...] following on from last weeks post I have taken a closer look at the common tools used to compress JavaScript. Below is a graph of the [...]