Nebula icon indicating copy to clipboard operation
Nebula copied to clipboard

Use stale-while-revalidate in Cache Control when available (🟧 awaiting Safari support)

Open chrisblakley opened this issue 5 years ago • 4 comments

https://www.chromestatus.com/feature/5050913014153216

Stale-While-Revalidate is coming as a Cache Control feature, so when that happens, consider updating the bundled .htaccess file to use it.

For reference, here is the current method of caching files as of March 31, 2019:

#Cache files for certain lengths of time
#1 YEAR
<FilesMatch "\.(ico|pdf|flv|png|gif|swf|jpg|jpeg|svg|woff|mp3|css|php|html|js)$">
	Header set Cache-Control "max-age=29030400, public"
</FilesMatch>

# 30 Days
<FilesMatch "\.(png|gif|swf|jpg|jpeg|svg|woff|woff2|mp3|css|js)$">
	Header set Cache-Control "max-age=2592000, public"
</FilesMatch>

# 2 DAYS
<FilesMatch "\.(xml|txt)$">
	Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>

# 10 HOURS
<FilesMatch "\.(php|html)$">
	Header set Cache-Control "max-age=36000, public"
</FilesMatch>

chrisblakley avatar Mar 31 '19 20:03 chrisblakley

This is the new syntax: Cache-Control: max-age=1, stale-while-revalidate=59

The number is in seconds: Indicates the client will accept a stale response, while asynchronously checking in the background for a fresh one. The seconds value indicates how long the client will accept a stale response. Note that the time does not start at the time of the request itself, but, for example, after max-age has elapsed. See "Keeping things fresh with stale-while-revalidate" for more information.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

chrisblakley avatar Feb 13 '21 19:02 chrisblakley

Waiting on Safari to support this before we can use it: https://caniuse.com/mdn-http_headers_cache-control_stale-while-revalidate

Screen Shot 2021-02-13 at 2 24 16 PM

chrisblakley avatar Feb 13 '21 19:02 chrisblakley

Still not supported in Safari...

chrisblakley avatar Aug 02 '22 14:08 chrisblakley

July 2023 still waiting on Safari...

Screen Shot 2023-07-24 at 5 18 06 PM

chrisblakley avatar Jul 24 '23 21:07 chrisblakley