Facebook and CSS

21.03.08

Filed Under: Facebook, Ruby on Rails

Facebook development is already a lot clunkier than straight web development, but one of the particularly irksome things about it is that external stylesheets are cached indefinitely, requiring a filename change to pull updated changes. While it would be great if they turned this off for apps marked as “in development”, we are instead stuck with the problem of working around it.

Fortunately, Rails makes it relatively easy. By default, Rails appends a file’s last-modified timestamp to the URL as a query parameter, which lets you perform cache-busting on old CSS files. Great stuff…except it only computes that timestamp once per mongrel session. This is a good thing for performance, but it’s a bad thing for facebook development.

Fortunately, there’s an easy way around it! I have my Facebook template, main.fbml.html, and at the top of it, I simply add:

<% ActionView::Base.computed_public_paths.clear if RAILS_ENV == "development" %>

Tada. Your file’s timestamp will be recomputed for each page load. This slows down page creation a bit, but it should speed up your development significantly, at least while you’re CSS hacking.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feed (this is global, not just for this entry)

Categories