Skip to main content
sitewarm
HTTP caching headers

What does Cache-Control max-age mean?

max-age sets how many seconds a response stays fresh after the origin generated it. Every cache, private or shared, may reuse it until then.

max-age is a `Cache-Control` response directive that sets the freshness lifetime in seconds. A cache may reuse the stored response without contacting the origin until its age exceeds that number. The age counts from when the origin generated the response, so time already spent in an upstream cache counts too.

Cache-Control: max-age=600

Freshness is a simple comparison in RFC 9111: a response is fresh while its freshness lifetime is greater than its current age. A downstream cache learns the time already spent upstream from the `Age` header, so a response with max-age=600 and Age: 590 has ten seconds of freshness left.

  • For shared caches such as a CDN, `s-maxage` overrides max-age.
  • When max-age is present, the `Expires` header is ignored.
  • max-age=0 makes the response stale immediately, so a cache has to revalidate it before reuse, usually with an `ETag`.

A stale response is not deleted. It stays in cache and can be revalidated cheaply, or served under `stale-while-revalidate`.

References

  1. RFC 9111: HTTP Cachinghttps://www.rfc-editor.org/rfc/rfc9111
  2. MDN: Cache-Controlhttps://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control

Warm your cache after every deploy

sitewarm requests the pages in your sitemap after a deploy and reports the cache state the CDN returns for each one, with the vantage point it was measured from.