Breaking the Rails static asset timestamp cache in development mode

Posted by warren
on Saturday, June 21

Rails automatically adds the File.mtime to static assets when using stylesheet_link_tag and javascript_include_tag. The file's mtime is cached to prevent excessive file system access... even in development mode. This is problematic in a Facebook canvas during development mode because often you won't immediately see the changes you make to your stylesheets and javascripts.

Here is a monkey patch you can throw into a config/initializers/break_asset_cache_in_dev_mode.rb to fix this:

if RAILS_ENV == 'development'
  require 'action_controller/dispatcher'
  ActionController::Dispatcher.before_dispatch do
    ActionView::Base.computed_public_paths.clear
  end
end
Comments

Leave a response