Content

ramblings of a coldfusion developer

Compressing JS and CSS with Ant

Thursday 13 September 2007 - Filed under Code

Mike Henke sent me a great link to this article: Building Web Applications With Apache Ant.

It's a great article but one section - "Minify your JavaScript and CSS files" really caught my eye. I've been using more and more jQuery code and related plugins in my projects (as well as more CSS) and to be able to compress these during deployment seems like a great bonus. Julien provides this example target:

CODE:

That looks easy enough! :)

Stephen Beal on the jQuery mailing list provided an issue to be aware of however:

While minification/packing rarely leads to semantic changes in JS
code, it does on occasion happen. It is easy to write code which might
run in uncompressed form yet may not be correct once minification
occurs (e.g., forgetting to add a semicolon after: var x = function()
{...};).

So you would need to test your application after compression to make sure everything was still working as expected.

Update:
Mike Henke has been busy: Adding JS/CSS compression and JS validation using YUI Compressor, JSLint, and jsmin to ant script

Tagged:

2007-09-13  »  Jim Priest

Talkback

  1. Mike Henke
    13 September 2007 @ 1:52 pm

    I wonder if you run the JSLint before and after the compress if you could see any compression issues. Just a thought (maybe save as a file to compare). Thanks for the mention.

Share your thoughts

Re: Compressing JS and CSS with Ant







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>