If you develop a website or webapplication it’s always a good idea to reduce the number of HTTP requests by combining the Javascript and CSS into single files. In addition those files should be minimized.
There is a cool Java-tool available which can help you: YUI-Compressor. It can be used from the commandline and is able to minimize Javascript and CSS files. A document about the CSS minification can be found here.
To automate the process of concatination and minification I wrote a little ANT script.
Ant Script for CSS and JS concatination and minification
All settings can be found in the head, pathes can be either relational or absolut. You have to download a current version of YUI-Compressor from here:
<!-- Settings for CSS -->
<property name="css.src-dir" value="path-to-css-source"/>
<property name="css.dest-dir" value="path-to-css-destination"/>
<property name="css.files" value="
css1.css,
css2.css
"/>
<!-- Settings for JS -->
<property name="js.src-dir" value="path-to-js-source"/>
<property name="js.dest-dir" value="path-to-js-destination"/>
<property name="js.files" value="
js1.js,
js2.js
"/>
<!-- General settings -->
<property name="yuicompressor-jar" value="path-to-yuicompressor.jar"/>
I defined three targets to provide a maximum of flexibility:
- all: Triggers css and javascript target
- css: Processes CSS
- javascript: Processes Javascript
Those targets can be called from commandline:
root@test:~# ant -f minify.xml TARGET
The CSS and Javascript target first concat the given CSS/JS files and then uses YUI-Compressor to minify them. The concated version will be deleted afterwards.
NOTE: YUI-Compressor version minor 2.4.4 have a bug which prevents the usage of Media-Queries in minified CSS!!!



