I have Rails serving my static assets. Most of them have hashes in their name and are served with far-future expiration dates. But for one file, I can't serve it with a hash in its name, so I need to control the expiration date.
I have this in my application.rb which applies to all static assets:
config.static_cache_control = "public, max-age=2592000"
Is there a way for me to have a different max-age for just one file? I know I can make a new middleware that comes after ActionDispatch::Static
and changes the value for certain files (see this writeup)... but then this will run for every single request, even those which aren't static assets. Is there a more elegant solution?
Rack::Static
solution here is working for me http://stackoverflow.com/questions/6962896/how-do-i-prevent-rails-3-1-from-caching-static-assets-to-rails-cach - John Bachir 2012-04-04 19:22
A bad technique can be to fix the URL of your file in your route.rb. You can define a Controller to this route fixing the cache_control you want and use send_data
method to server the file.