File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
railties/lib/rails/generators/rails/app/templates/config/environments Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,20 @@ Rails.application.configure do
17
17
config.action_controller.perform_caching = true
18
18
<%- end -%>
19
19
20
- # Cache assets for far-future expiry since they are all digest stamped.
21
- config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" }
20
+ # Cache digest stamped assets for far-future expiry.
21
+ # Short cache for others: robots.txt, sitemap.xml, 404.html, etc.
22
+ config.public_file_server.headers = {
23
+ "cache-control" => lambda do |path, _|
24
+ if path.start_with?("/assets/")
25
+ # Files in /assets/ are expected to be fully immutable.
26
+ # If the content change the URL too.
27
+ "public, immutable, max-age=#{1.year.to_i}"
28
+ else
29
+ # For anything else we cache for 1 minute.
30
+ "public, max-age=#{1.minute.to_i}, stale-while-revalidate=#{5.minutes.to_i}"
31
+ end
32
+ end
33
+ }
22
34
23
35
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
24
36
# config.asset_host = "http://assets.example.com"
You can’t perform that action at this time.
0 commit comments