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 […]
June 23rd, 2011 at 7:54 am
I tried to run the compression using the ant task and I get the following error:
/tmp/sns/wfn-static/build.xml:84: java.io.IOException: No such file or directory
at java.io.File.createNewFile(File.java:883)
at com.zutubi.ant.shrinksafe.ShrinksafeTask.execute(ShrinksafeTask.java:107)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:600)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
September 11th, 2012 at 8:37 am
Hello would you mind sharing which blog platform you’re working with? I’m planning to start my own blog soon but I’m having a tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something unique.
P.S Apologies for being off-topic but I had to ask!