Ant task for minifying JS/CSS files using YUI Compressor

Recently, while working on a project, I had the need for minifying a set of Javascript and CSS files. Although the project was in HTML5 with no server side component, I had set up the build process using Apache Ant.

I looked online for an ant library that could accomplish this and came across one that was almost exactly what I was looking for. It could minify JS files using YUI Compressor but lacked a couple of features I required. So, I went through the library’s source code and added the following features

  • Minification option for CSS files
  • Option to delete original source files after minification

Since other people might want to use these additional features, I’ve made the modified library open source on GitHub:

The README file describes the available options and how to use them. There’s also an example folder with a working ant project for JS/CSS minification. My code is based on the yui-compressor-ant-task hosted on google code.

onclick or ONCLICK or onClick?

HTML is case-insensitive and therefore the casing of event handler names in your HTML documents is irrelevant. E.g. you can use onclick, ONCLICK, onClick or event oNcLiCk for your event handler name. However, XHTML is not so liberal and stipulates that all event handler names should be lowercase (e.g. onclick=”…”). Therefore, to make your HTML pages XHTML compliant, always use lowercase event handler names.

Declaring Constants in Java/JavaScript/ActionScript

This has confused me some times in the past, so I thought I’d put it here for easy reference.


final int VALUE = 10;


const VALUE = 10;


const VALUE:Number = 10;


The point of confusion is that const is a reserved word in Java but is not used for declaring constants (yet!). Java uses the final keyword for this purpose.