Just monkey patched Sprockets in our Rails 3.2.9 app to override the Cache-Control header for html assets that we need to tweak more often in development, but that we don’t want to use digests/fingerprinting with:
Sprockets 2.x patch
private alias_method :sprockets_headers, :headers def headers(env, asset, length) sprockets_headers(env, asset, length).tap do |headers| # cache-bust .html assets because in our case they are frequently AngularJS templates we need to tweak if !path_fingerprint(env["PATH_INFO"]) && asset.pathname.basename.to_s['.html'] headers["Cache-Control"] = "max-age=0, private, must-revalidate" end end end end
Would the ability to configure “Cache-Control” and other headers (or add headers) in responses for assets in Sprockets be helpful to have available in Rails, or is it just assumed that if you need that level of control, you’ll fix it elsewhere with nginx, apache, etc.?
Why I’m asking is that Heroku shows here how to change expiry of actions:
but, I couldn’t find anywhere that talked about how to expire assets other than using digests/fingerprinting, until I came across server.rb in sprockets and realized that it didn’t look like it was possible without monkey patching or using another gem that would override the headers.