Skip to main content
sitewarm
HTTP caching headers

What do Cache-Control public and private mean?

private lets only the browser cache a response. public lets shared caches such as a CDN store it, even for requests that carry Authorization.

private and public are `Cache-Control` response directives that decide who may store a response. private means only a private cache, such as the browser, may store it, so a CDN must not. public means any cache may store it, even when it would not be cacheable by default, such as a response to an authenticated request.

Cache-Control: private, max-age=300

Cache-Control: public, s-maxage=3600

The Authorization case matters for CDNs. RFC 9111 (section 3.5) says a shared cache must not reuse a response to a request with an Authorization header unless the response carries a directive that allows shared caching, such as public, `s-maxage` or `must-revalidate`.

  • public is not needed for ordinary cacheable responses: a `max-age` is enough to make them storable.
  • private is not a security control. It keeps a response out of shared caches, but the browser still stores it. Use `no-store` for data that must not persist.
  • Cookies personalize pages without Authorization. Cloudflare, for example, does not cache a response that sets Set-Cookie by default.

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
  3. Cloudflare: Default cache behaviorhttps://developers.cloudflare.com/cache/concepts/default-cache-behavior/

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.