Skip to content
BENIBIX Learn

Cache-Control Header

Infrastructure🌍 Web Serving & NginxProxies and Caches

Also known as Cache-Control, HTTP Caching, Cache Headers

An HTTP header. It tells browsers and CDNs how long they may keep a copy of a file.

Think of it like

It is like the best-before date on a milk carton. It tells you how long you can keep it.

Example

Jack's logo rarely changes, so his server sends max-age=86400 with it. Browsers keep it for a day before they ask again.

Why it matters

Good caching makes repeat visits fast and saves bandwidth. Bad caching shows people old pages.

Definition

Cache-Control is an HTTP header that tells browsers, CDNs and proxies how long they may keep and reuse a copy of a file. The max-age part gives the time in seconds. While the copy is fresh, it is used without asking the server again. The no-store part means never keep a copy at all. Web servers can set it for each kind of file.

Example code

http
Cache-Control: max-age=86400
86,400 seconds is one day. Until then, the browser uses its own copy.
This header tells the CDN and the browser how long their copy stays fresh.

Common mistake

Giving a long max-age to a file and then editing it under the same name. Visitors keep the old one until the time runs out.

Key takeaways

  1. 1
    How long. max-age, in seconds.
  2. 2
    Who keeps it. Browsers and CDNs.
  3. 3
    Never keep. no-store, for private data.