The goal of this small project is to simplify and improve the way static resources are optimized before being deployed to the webserver for public access.
What does it do?
- Version the resulting files: by adding a checksum of the resulting file to the filename (this is better than e.g. a new version for each deployment, since those files might not have been changed). Except for the HTML files.
By the way, all source files are first copied to a distribution folder before being processed (so it doesn't touch your source files).
- Ant-Contrib (included)
- Closure Compiler (included)
- YUI Compressor (included)
- HTML Compressor (included)
First of all, it is probably best to clone this project, and run
ant from the build folder. Looking at the result should give a good impression. The build script is also documented. Having that said... An HTML file (index.html in this example) might contain the following:
<!--##OPTIMIZE_CSS##--> <link rel="stylesheet" href="css/normalize.css" type="text/css"/> <link rel="stylesheet" href="css/stylesheet.css" type="text/css"/> <link rel="stylesheet" href="css/typography.css" type="text/css"/> <!--##OPTIMIZE_CSS##-->
When the build script has run, this will be replaced by:
<link rel="stylesheet" href="http://static.example.org/css/stylesheet-468fb262.css" type="text/css"/>
And the actual file being referenced here (
<script> elements), yet here we can also simply use strings (for use in script loaders). Please refer to /src/index.html for an example.
There is quite some flexibility using options, such as:
- the files to be concatenated and optimized (e.g. in development there might be debug.css that should not be included)
- the order of the files to be concatenated
- optional: the filename of the resulting optimized file (default:
- optional: the checksum of the optimized file replaces
#characters in the new filename (e.g.
- optional: the tags surrounding the
- optional: the url to the resulting file (here:
build.properties file are the files you should modify. The
optimize.xml file containing
<macrodef>s (to be used as Ant tasks) is meant to be included in existing build scripts. Of course, you can also use the provided files as a starting point and work from there.
Ideas for improvement
- Ant task to optimize images (using e.g. PNGOUT).
- Provide the option to automatically resolve an ordered fileset within the wrapping tags (no need to provide a
Have more or better ideas? Tell me about it! I'm happy to try and implement yours or even better, accept your pull requests.
The name of this project is arbitrarily taken from a wild cat species. It is a flexible animal; an agile climber and a good swimmer.
Copyright (c) 2011 Lars Kappert, WebPro. This software is licensed under the MIT License.