Skip to content

Commit 6b5a125

Browse files
committed
Improve default public file server cache-control further
Set `immutable` for digested assets, this improve modern browsers behavior, saves them from ever revalidating. Set `stale-while-revalidate` for non-digested files. This allows caching proxies to ever only revalidate at most once per minute and asyncrhonously.
1 parent ed7e061 commit 6b5a125

File tree

1 file changed

+5
-2
lines changed
  • railties/lib/rails/generators/rails/app/templates/config/environments

1 file changed

+5
-2
lines changed

railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ Rails.application.configure do
2222
config.public_file_server.headers = {
2323
"cache-control" => lambda do |path, _|
2424
if path.start_with?("/assets/")
25-
"public, max-age=#{1.year.to_i}"
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}"
2628
else
27-
"public, max-age=#{1.minute.to_i}"
29+
# For anything else we cache for 1 minute.
30+
"public, max-age=#{1.minute.to_i}, stale-while-revalidate=#{5.minutes.to_i}"
2831
end
2932
end
3033
}

0 commit comments

Comments
 (0)