-
-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache-Control
boilerplate with extensive control (#325)
- Loading branch information
Showing
6 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# ---------------------------------------------------------------------- | ||
# | Cache Control | | ||
# ---------------------------------------------------------------------- | ||
|
||
# Serve resources with appropriate cache control directives. | ||
# | ||
# The `Cache-Control` header field holds directives (instructions) that control | ||
# caching in browsers and shared caches (e.g. Proxies, CDNs). | ||
# Its use targets web performances improvement by specifying the expected | ||
# client and network caches behaviors. | ||
# | ||
# The usable cache directives are listed here: | ||
# https://www.iana.org/assignments/http-cache-directives/http-cache-directives.xml | ||
# | ||
# The cache directives are documented here: | ||
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#response_directives | ||
# | ||
# (!) Enable and configure this configuration with care. | ||
# Default values should embrace conformance for static files and simple | ||
# apps, but cache control definition at backend level is highly preferred. | ||
# Incorrect directives can lead to data leaks, or can degrade performances. | ||
# | ||
# More specifically, in-depth understanding on `public` vs `private` | ||
# directives meanings is highly recommended. A resource with `public` will | ||
# be cached by shared caches like CDN, even if a user session is active. | ||
# | ||
# (!) The config directive `Header` must be used with the appropriate action. | ||
# Depending on the need, `merge` keeps the current value, if any, of | ||
# `Cache-Control` header, while `set` reset the value including the one | ||
# added by `ExpiresByType` directive in the cache expiration config file | ||
# h5bp/web_performance/cache_expiration.conf. | ||
# https://httpd.apache.org/docs/current/mod/mod_headers.html#header | ||
# | ||
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control | ||
# https://www.rfc-editor.org/rfc/rfc9111.html | ||
# https://www.rfc-editor.org/rfc/rfc8246.html | ||
# https://www.rfc-editor.org/rfc/rfc5861.html | ||
# https://www.iana.org/assignments/http-cache-directives/http-cache-directives.xml | ||
# https://cache-tests.fyi/ | ||
|
||
<IfModule mod_headers.c> | ||
|
||
# Default | ||
Header merge Cache-Control "public, immutable, stale-while-revalidate" "expr=%{resp:Cache-Control} == 'max-age=31536000'" | ||
|
||
# No content | ||
Header merge Cache-Control "no-store" "expr=-z %{CONTENT_TYPE}" | ||
|
||
# Manifest files | ||
Header merge Cache-Control "public" "expr=%{CONTENT_TYPE} =~ m#application/manifest\+json#i" | ||
Header set Cache-Control "no-cache" "expr=%{CONTENT_TYPE} =~ m#text/cache-manifest#i" | ||
|
||
# Assets | ||
Header merge Cache-Control "public, immutable, stale-while-revalidate" "expr=%{CONTENT_TYPE} =~ m#image/x-icon#i" | ||
|
||
# Data interchange | ||
Header merge Cache-Control "public, stale-while-revalidate" "expr=%{CONTENT_TYPE} =~ m#application/(atom|rdf|rss)\+xml#i" | ||
|
||
# Documents | ||
Header set Cache-Control "no-cache, private, must-revalidate" "expr=%{CONTENT_TYPE} =~ m#text/(html|markdown|calendar)#i" | ||
|
||
# Data | ||
Header set Cache-Control "no-cache" "expr=%{CONTENT_TYPE} =~ m#json|xml#i && %{CONTENT_TYPE} !~ m#/(atom|rdf|rss|manifest|svg)\+#i" | ||
|
||
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters