Introducing the Sprite-Factory Gem

Share this article

It is a well established performance best practice for a web page to minimize the number of HTTP requests it makes for assets like images, javascript files and stylesheets. In fact, its Rule #1 on Steve Souders High Performance Web Sites.

In the latest version of Rails, these practices are being formalized for javascript and css with the asset pipeline, using the sprockets and sass libraries to combine multiple smaller files into a single unified (and minified) asset file in production mode.

But for images, where the best practice is to use css sprites, Rails does not (yet) have a best-practice solution. Many developers are using manual tools, that require uploading files to a 3rd party web service such as Sprite Cow or SpriteMe when it would be better to have a fully automated system built into a Rake task or command line script.

Introducing the sprite-factory gem.

The sprite factory is a ruby library that can be used to easily generate CSS sprites in any ruby application. It combines individual image files from a directory into a single unified sprite image and creates an appropriate CSS stylesheet for use in your web application.

The library provides:

  • both a ruby API and a command line script
  • many customizable options
  • support for any stylesheet syntax, including CSS and Sass.
  • support for any image library, including RMagick and ChunkyPNG.
  • support for different layout strategies – horizontal, vertical or packed rectangles.

You can find install and usage instructions on github

This gem was originally developed as part of the LiquidPlanner online project management web app. So thanks go out to them for allowing me to open source the original version.

Jake GordonJake Gordon
View Author

Senior Software Engineer at, building the best online project management application during the day, and experimenting with HTML5 games by night!

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form