Erik A. Hanson's Weblog

A Ruby Script to Concatenate and Compress Javascript Files

Posted: October 16th, 2007    Tags: Javascript, Web development

I’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



One Response to “A Ruby Script to Concatenate and Compress Javascript Files”

  1. Erik A. Hanson » Blog Archive » A Rake Task to Concatenate and Compress Javascript Files Says:

    [...] 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 [...]

Leave a Reply

About Me

I'm a software developer and consultant in San Francisco. I mostly develop web apps in Javascript, Java and Rails. There's a little more about me on my LinkedIn profile.

Recent Projects

wshlst.com: a group-oriented wish list website.

BoardsConsult​/​RotationTracker: a site to help medical residents prepare for the U.S. Medical Licensing Exam, and a related site to help medical schools evaluate and track the progress of the residents in their programs.

Jobs

I moderate a few completely free jobs mailing lists with RSS feeds and zero spam: XP jobs, Rails jobs and Mac development jobs. Also, my pals at Pivotal Labs have agile Rails and Java job openings.

Plug: Web Hosting

Looking for cheap shared web hosting and/or domain registration? I've been using DreamHost for years and I've been very happy with them. They offer tons of disk space and bandwidth, one-click installation for apps like WordPress and Gallery, unlimited domains, thousands of email accounts, private domain registration, and more. They are also a nice bunch of folks, not some big dumb company.