Series: My arsenal of plug-ins - Bundle-fu

November 12th, 2007

UPDATE: Looks like they’ve added functionality like this in Rails 2.0 using <%= stylesheet_link_tag( “main”, “forms”, “utilities”, { :cache => “frontend” } ) %>. Check out the latest release candidate w/ notes.

After writing about all of the nifty Firefox extensions I use on a daily basis, I had an idea to detail the Rails plug-ins and gems I’m in love with. This marks the beginning.

Bundle-fu fake logo

Tim Harper’s Bundle-fu plug-in was just the thing I was looking for while trying to cut down on the number of server requests per page. All you have to do is wrap both your stylesheets & javascripts in your layout file into separate code blocks, and bundle-fu will take care of the rest.

layout.rhtml

1
2
3
4
5
<% bundle( { :name => "styles" } ) do -%>
  <%= stylesheet_link_tag( "common", :media => "screen" ) %>
  <%= stylesheet_link_tag( "main",   :media => "screen" ) %>
  ... etc.
<% end -%>

This outputs a one-liner pointing to one lovely file all your css:

1
<link href="/stylesheets/cache/styles.css?20071111142032" media="screen" rel="Stylesheet" type="text/css" />

Here’s the install:

1
script/plugin install http://bundle-fu.googlecode.com/svn/tags/bundle_fu

Make sure to read the caveats page as there is a few (as always). I believe the largest is the fact that conditionally loaded stylesheets for Internet Explorer need to be outside of the code block.

Sorry, comments are closed for this article.