---
title: "Rails Cache-Control"
description: "For enabling setting cache-control headers of static assets and using a CDN on Heroku:"
canonical: https://oozou.com/til/rails-cache-control-77
locale: en
date: 2020-10-27
topic: ruby-on-rails
---

# Rails Cache-Control

> For enabling setting cache-control headers of static assets and using a CDN on Heroku:

Published: 2020-10-27 · Topic: [ruby on rails](https://oozou.com/til-topics/ruby-on-rails) ([markdown](https://oozou.com/til-topics/ruby-on-rails.md))

For enabling setting cache-control headers of static assets and using a CDN on Heroku:

```rails
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.public_file_server.headers = {
  'Cache-Control' => 'public, max-age=31536000',
  # You need to enable this (or set it to your domain) for fonts to work
  'Access-Control-Allow-Origin' => '*'
}

if ENV['ASSET_HOST'].present?
  config.action_controller.asset_host = ENV['ASSET_HOST'] # 'https://cdn.example.com'
end
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
