Reputation: 32392
I'm trying to set an Expires header for my static assets server by Heroku, and I haven't found any information on how to do this...
All the information I've found explains how to set the Cache
header:
Cache-Control:public, max-age=31536000, no-transform
and refers to that as the Expires
header, but that's not the Expires header.
When an asset has the Expires
header set, the browser uses its cached version, and doesn't even hit the server to check if there's a new version.
With the Cache
header, I'm seeing hits on my logs for the static files that should be cached.
How can I set an Expires
header, for static assets?
Thank you!
Upvotes: 0
Views: 1311
Reputation: 381
You don't really need to set the expires header anymore. For many reasons some legacy some related to CDN, there are more than one HTTP header controlling how an asset is cached. This includes Cache-Control, Expires, ETag and a few really old ones. You don't need all of them. These days, you only need Cache-Control for a reasonably modern browser. Some people like to set Expires for compatibility. But that's kind of over-valued.
To set cache-control, inside config/environments/production.rb, set these lines
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.static_cache_control = "public, max-age=31536000"
Upvotes: 2