HTTP Caching Guide

Cache-Control directives, validators, and practical caching flows.

Cache-Control Directives

Key / CodeDescription
max-ageFreshness lifetime in seconds.
no-storeDo not store response at all.
no-cacheStore but revalidate before use.
publicCacheable by shared caches/CDNs.
privateCacheable only by the browser.
stale-while-revalidateServe stale while revalidating.

Validators

Key / CodeDescription
ETagStrong/weak identifiers for resource versions.
Last-ModifiedTimestamp of last modification.
If-None-MatchRevalidate using ETag.
If-Modified-SinceRevalidate using Last-Modified.

Example

Cache-Control: public, max-age=60, s-maxage=300, stale-while-revalidate=30
ETag: "v1-abc"
Vary: Accept-Encoding

Common Caching Strategy

For HTML pages, keep browser freshness short and rely on validators. For versioned static assets, use a very long max-age with immutable file names. For API responses, decide whether the response is public or private first, then combine Cache-Control with ETag or Last-Modified so stale content can be revalidated cheaply.

Knowledge is power.