2

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?

John Bachir
  • 22,495
  • 29
  • 154
  • 227

1 Answers1

0

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.

shingara
  • 46,608
  • 11
  • 99
  • 105
  • considered something like that as well... a messy path to go down but possibly the best solution in the end – John Bachir Apr 04 '12 at 19:22
  • it's the most simplest if you don't want add a Middleware. Or you need hack the ActionDispatch::Static middleware to do the job. Maybe replace it by example. – shingara Apr 05 '12 at 07:42