tags:

views:

33

answers:

2

I am using ANT to deploy build in to Tomcat Server. I Want to compress the static files CSS and JS only when i deploy to the server.

any suggestion?

+1  A: 

This blog post about using YUI compressor to minify JS/CSS using Ant might help you.

Thilo
+2  A: 

You can do something like that as part of the build (using YUI Compressor)

<target name="js.minify">
    <apply executable="java" parallel="false">
        <fileset dir="." includes="foo.js, bar.js"/>
        <arg line="-jar"/>
        <arg path="yuicompressor.jar"/>
        <srcfile/>
        <arg line="-o"/>
        <mapper type="glob" from="*.js" to="*-min.js"/>
        <targetfile/>
    </apply>
</target>

<target name="css.minify">
    <apply executable="java" parallel="false">
        <fileset dir="." includes="*.css"/>
        <arg line="-jar"/>
        <arg path="yuicompressor.jar"/>
        <arg line="--line-break 0"/>
        <srcfile/>
        <arg line="-o"/>
        <mapper type="glob" from="*.css" to="*-min.css"/>
        <targetfile/>
    </apply>
</target>

Check out this article for more info: http://www.julienlecomte.net/blog/2007/09/16/

Strelok
Is YUI Compressor is open source?
Soft
It's available under the BSD License, so yes it is open source and free to anyone (if that's what you are asking). http://developer.yahoo.com/yui/
Strelok
Just a quick intrusion—you may also want to look at http://code.google.com/p/jslint4java/ for running JSLint from ant.
Dominic Mitchell