Notes: Caching

Browser Cache

HTTP headers used for browser caching. The following is generally a good one to use for a balance of fresh files + cache efficiency.

Cache-Control: public, max-age=0, s-maxage=60, must-revalidate

public
The response can be cached by both a shared proxy (e.g CDN cache) and the browser.
private
The response should not be cached by a shared proxy, only by the browser.
max-age=0
The number of seconds both a shared proxy or browser should cache the response, before being considered stale.
s-maxage=60
The number of seconds just a shared proxy should cache the response, before being considered stale.
must-revalidate
Once a file is considered stale, the browser or proxy will re-request the file whilst also sending the etag hash of the current file it has (via the request header If-None-Match=<etag provided with the initial file repsonse>). The server or shared proxy will compare the hash with its current file and send back either a 304 Not Modified header response, or a 200 Ok response with the contents of the updated file. Including an updated etag header for the new file.

The kind of traffic for doing a revalidation request will be very low (under 1kb), its just headers.

Open the network tab on this page and check, make sure "disable cache" is unticked, and press refresh.

Browser <---> Shared Proxy <---> Server

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