A Ruby Script to Concatenate and Compress Javascript Files
Posted: October 16th, 2007 Tags: Javascript, Web developmentI’ve got an HTML page that includes a bunch of Javascript files, which makes development easy but which hurts performance in production.
The standard solution is to concatenate all the Javascript files into one big file and then compress it. I wanted it to be automated of course, and I wanted to do it at deploy-time, not at run-time.
So I wrote a little script that figures out what Javascript files are being included in the HTML page, compresses them with the YUI Compressor, concatenates them into a file named after the newly-compressed and -concatenated Javascript’s MD5 hash, and creates a copy of the original HTML page that references the new Javascript file instead of the old ones.
It’s pretty specific to my app’s needs, but with some minor tweaking, it should be useable on other projects. Check it out: minify.rb
March 2nd, 2008 at 11:15 pm
[...] while ago, I wrote about a Ruby script to concatenate and compress Javascript files for my wshlst application. I’ve changed things around a bit since that article, so I thought [...]