HTTP - Cache (Cache-Control Header, Bursting, …)

About

When sending a response, several headers have an influence / control over the cache store, we call them cache control headers

The cache control header are:

Name Description
Cache-Control Define the scope and age of the response (as replaced pragma)
Expires Define an expiration date after which the response is considered stale.
Date Used to detect clock drift and calculate expiration date (if not set based on the max-age of Cache-Control )
ETag and last-modified Digest Value and time that are send back by the client in a conditonal get request to check if the resources have changed
Vary Add an header value in the cache key

Caching does not mean not hitting your web server

If the browser cache (or any other intermediate cache - proxy) has cached a file, it may send a conditional get request waiting for a 304 https status - Not Modified giving it the possibility to use its cache.

Why ? Cache entries might persist for arbitrarily long periods, regardless of expiration times. Ref Thus, a browser cache might attempt to validate a expired cache entry.

Note on Cache Bursting

Cache bursting is a technique that permits to control the cache of static resources where you integrates in the URL of the resource a versioning element of the resource such as:

Because the cache key is based on the URL, the new URL will be different and the cache will not be used.

If the new version used the same URL, because of the cache, the page may used the old one.

For more information, see the specific article: Web HTTP - Cache Bursting (Content fingerprinting)

Documentation / Reference


Powered by ComboStrap