Understanding max-age in Cache-Control

Learn how the max-age directive controls how long a browser caches a response before treating it as stale and requesting a fresh copy from the origin server.

Basics

Detailed Explanation

What Is max-age?

max-age is the most fundamental Cache-Control directive. It specifies the maximum amount of time, in seconds, that a response is considered fresh by the browser's cache. Once the max-age duration expires, the cached response becomes stale, and the browser must revalidate or fetch a new copy.

How It Works

Cache-Control: max-age=3600

This tells the browser: "You may serve this response from cache for up to 3600 seconds (1 hour) without contacting the server."

The Freshness Lifecycle

  1. Response received — the browser stores the response and starts a freshness timer
  2. Within max-age — subsequent requests are served instantly from cache (no network request)
  3. After max-age expires — the response is stale; the browser sends a conditional request (If-None-Match / If-Modified-Since) to the server
  4. Server responds 304 — the cached version is still valid; timer resets
  5. Server responds 200 — new content replaces the cached version

Common max-age Values

Value Duration Typical Use
0 None Force revalidation on every request
60 1 minute Rapidly changing API data
3600 1 hour Semi-dynamic content
86400 1 day Infrequently updated resources
604800 1 week Stable assets
31536000 1 year Immutable versioned files

max-age vs Expires

The older Expires header uses an absolute date, which requires synchronized clocks between server and client. max-age is relative and always wins when both are present. Modern applications should use max-age exclusively.

Use Case

Every web application benefits from understanding max-age. When you serve a static CSS file with max-age=31536000, the browser caches it for a full year, eliminating network requests entirely. When you serve an API response with max-age=60, you reduce origin server load while ensuring data stays reasonably fresh. Choosing the right max-age value is the first step in any caching strategy.

Try It — Cache-Control Builder

Open full tool