Search code examples
ruby-on-railscachingasset-pipelineamazon-cloudfront

Rails 3.1 Assets, Cache-Control, Max-Age and Expires headers


I currently have an app on Heroku Cedar stack running with Unicorn.

I also have CloudFront configured as a custom origin to host my css/js assets. However it seems like no matter which way I configure the static/assets for Rails it will not allow me to set the Cache-Control, Max-Age or Expires headers.

This is important as the headers are pass-through with CloudFront and if I can't set them CloudFront won't cache them properly.


Solution

  • Try adding this to your environments/production.rb file.

    config.static_cache_control = "public, max-age=3600"