Cache-Control is the HTTP response header that sets caching rules for browsers, CDNs and other intermediaries. It says whether a response may be stored, by whom, for how long, and when it must be revalidated. Well-set caching makes repeat visits and navigations faster, reduces server load, and lets crawlers that support conditional requests skip downloading unchanged pages.
Common directives
The header takes a comma-separated list of directives. A few cover most needs.
- max-age=N: fresh for N seconds in any cache
- s-maxage=N: overrides max-age for shared caches such as CDNs
- no-cache: may be stored, but must be revalidated before each use
- no-store: must not be stored at all
- private: only the browser may store it, not shared caches
- immutable: the file will never change at this URL
- stale-while-revalidate=N: serve a stale copy while fetching a fresh one
A typical setup
Versioned static assets, whose filenames include a content hash, can be cached for a long time because a change produces a new URL. HTML usually gets a short lifetime or revalidation so updates appear quickly.
# Fingerprinted assets: /assets/app.3f9a1c.js
Cache-Control: public, max-age=31536000, immutable
# HTML pages
Cache-Control: public, max-age=0, s-maxage=300, stale-while-revalidate=60Caching and crawlers
Google documents that its crawlers support HTTP caching through conditional requests: if a server sends ETag or Last-Modified headers, Googlebot can ask whether the page changed and receive a 304 Not Modified response instead of the full page. This saves resources on both sides. Cache-Control itself mainly affects browsers and CDNs; it does not control how often Google recrawls a page.
Example
Long cache, unversioned files
Mossbeacon sets a one-year max-age on every file under /static, including a stylesheet with a fixed filename. After a redesign, returning visitors see the old styles mixed with new HTML. The fix is to add content hashes to asset filenames so each version has its own URL, and keep the long lifetime.
Common mistakes
Long max-age on unversioned assets
Without a hash in the filename, browsers keep using the old file until it expires. Version files before caching them for long.
Caching personalized HTML publicly
Pages with user-specific content must be private or no-store, or a CDN may show one user's page to another.
Questions
Not directly. It improves speed for returning visitors and reduces server load, which can help user experience metrics and crawl reliability.