Minify and Concatenate JavaScript plus CSS files
Yesterday I wrote this little Makefile to minify and concatenate multiple JavaScript and CSS files. It depends on the YUI Compressor JAR.
Since the browser can open at most 5 concurrent connections to the same host, and I had a web application depending on 20+ of these files, the first request was taking too long.
The only solution I saw was minifying and concatenating them to serve only 2 files (1 JS + 1 CSS). And that’s what I did.
Here’s how it works:
$ make
[css] static/css/first.css
[css] static/css/second.css
[css] static/css/third.css
[css] static/css/and_so_on.css
[tag] @import url("static/css/all.css");
[js] static/js/first.js
[js] static/js/second.js
[js] static/js/third.js
[js] static/js/and_so_on.js
[tag] <script type="text/javascript" src="static/js/all.js"></script>
Done.
Simple huh?
Now, replace those bunch of includes, and be happy!
Advertisement