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
if Rails.env.development?
module Sprockets
module Server
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
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:
https://devcenter.heroku.com/articles/http-caching-ruby-rails
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.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/fgvsaflGLIcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.