Breadcrumbs

Sprockets: JavaScript Dependency Management and Concatenation

Sam Stephenson of 37signals has released Sprockets (external link), a Ruby library that helps to organise multiple JavaScript files neatly into one single, deployable file. Sprockets takes multiple JavaScript files from across directories and generates one single file that contains all of them. The obvious advantage is that you, as a developer, have the ability to organise your JavaScript into multiple files without the extra HTTP requests. It is certainly a very speedy way to serve JavaScript to your users.

Even though I have never developed any websites that are JavaScript-heavy, I like the idea of maintaining a multiple file organisation, whilst serving all the files as one single file to the end user. Simply, the reduction in HTTP requests is beneficial enough. Sprockets is packaged as a Ruby library, but there is a stand-alone CGI script as well. It seems pretty geared towards Ruby on Rails users, which makes sense, fitting into 37signals' little Rails-Prototype world they have created.

The blog post on Signal vs. Noise about Sprockets (external link) has a video that explains how Sprockets works for anyone who is interested. Personally, it looks like a bit of an overkill and probably could be executed more easily. Nonetheless, it looks like a nifty tool for Ruby on Rails websites that are JavaScript-heavy.

Concatenating files to reduce HTTP requests is not a new idea and can be applied to CSS and to web files in general. CSS::Squish (external link) is a Perl script that compacts multiple CSS files into one big file. Even more general, modconcat (external link) is an Apache module that concatenates files together utilising the URL. I also found a pretty good blog post on ArtzStudio (external link) that discusses various concatenation utilities.

Overall, I don't think that I will find myself using Sprockets, but the concept of concatenation is intriguing nonetheless. I might look further into some of the other concatenation utilities I discovered, particularly to combine CSS files. Also, if anyone has any experience with file concatenation please feel free to post about it in the comments below.

Comments