Use proper `Cache-Control` values
This commit is contained in:
parent
8927afb6f9
commit
9fa553bbc4
|
@ -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;
|
||||
|
|
28
nginx.conf
28
nginx.conf
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue