Use proper `Cache-Control` values
This commit is contained in:
parent
8927afb6f9
commit
9fa553bbc4
|
@ -2,32 +2,15 @@
|
||||||
# | Cache Control |
|
# | Cache Control |
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
# TBD
|
# Serve resources with appropriate cache control.
|
||||||
#
|
#
|
||||||
# (1) TBD
|
# The `Cache-Control` header field holds directives (instructions) that control
|
||||||
#
|
# caching in browsers and shared caches (e.g. Proxies, CDNs).
|
||||||
# (2) TBD
|
|
||||||
#
|
|
||||||
# (3) TBD
|
|
||||||
#
|
#
|
||||||
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
||||||
|
# https://www.rfc-editor.org/rfc/rfc9111.html
|
||||||
map $sent_http_content_type $cache_control {
|
# https://www.rfc-editor.org/rfc/rfc8246.html
|
||||||
# (1)
|
# https://www.iana.org/assignments/http-cache-directives/http-cache-directives.xml
|
||||||
default "private, must-revalidate";
|
# https://cache-tests.fyi/
|
||||||
|
|
||||||
# (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";
|
|
||||||
}
|
|
||||||
|
|
||||||
add_header Cache-Control $cache_control;
|
add_header Cache-Control $cache_control;
|
||||||
|
|
28
nginx.conf
28
nginx.conf
|
@ -102,6 +102,34 @@ http {
|
||||||
# Specify file cache expiration.
|
# Specify file cache expiration.
|
||||||
include h5bp/web_performance/cache_expiration.conf;
|
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.
|
# Add X-Frame-Options for HTML documents.
|
||||||
# h5bp/security/x-frame-options.conf
|
# h5bp/security/x-frame-options.conf
|
||||||
map $sent_http_content_type $x_frame_options {
|
map $sent_http_content_type $x_frame_options {
|
||||||
|
|
Loading…
Reference in New Issue