Use proper `Cache-Control` values

This commit is contained in:
Léo Colombaro 2022-11-03 22:50:13 +00:00
parent 8927afb6f9
commit 9fa553bbc4
2 changed files with 35 additions and 24 deletions

View File

@ -2,32 +2,15 @@
# | Cache Control |
# ----------------------------------------------------------------------
# TBD
# Serve resources with appropriate cache control.
#
# (1) TBD
#
# (2) TBD
#
# (3) TBD
# The `Cache-Control` header field holds directives (instructions) that control
# caching in browsers and shared caches (e.g. Proxies, CDNs).
#
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
map $sent_http_content_type $cache_control {
# (1)
default "private, must-revalidate";
# (2)
~*text/html "public, immutable";
~*text/css "public, immutable";
~*text/javascript "public, immutable";
~*xml "public, immutable";
~*application/pdf "public, immutable";
# (3)
~*audio/ "public, immutable";
~*image/ "public, immutable";
~*font/ "public, immutable";
~*video/ "public, immutable";
}
# https://www.rfc-editor.org/rfc/rfc9111.html
# https://www.rfc-editor.org/rfc/rfc8246.html
# https://www.iana.org/assignments/http-cache-directives/http-cache-directives.xml
# https://cache-tests.fyi/
add_header Cache-Control $cache_control;

View File

@ -102,6 +102,34 @@ http {
# Specify file cache expiration.
include h5bp/web_performance/cache_expiration.conf;
# Add Cache-Control.
# h5bp/web_performance/cache-control.conf
map $sent_http_content_type $cache_control {
default "public, immutable, stale-while-revalidate";
# No content
"" "no-store";
# Manifest files
~*application/manifest\+json "public";
~*text/cache-manifest ""; # `no-cache` set by `expire`
# Assets
~*image/svg\+xml "public, immutable, stale-while-revalidate";
# Data interchange
~*application/(atom|rdf|rss)\+xml "public, stale-while-revalidate";
# Documents
~*text/html "private, must-revalidate";
~*text/markdown "private, must-revalidate";
~*text/calendar "private, must-revalidate";
# Data
~*json ""; # `no-cache` set by `expire`
~*xml ""; # `no-cache` set by `expire`
}
# Add X-Frame-Options for HTML documents.
# h5bp/security/x-frame-options.conf
map $sent_http_content_type $x_frame_options {