Skip to content
IT glossary
BackendUpdated December 3, 2026

HTTP caching

HTTP-кэширование

Browsers and intermediaries can save HTTP responses and reuse them for later requests. HTTP caching rules determine when a saved response is usable as is and when it needs to be checked for changes.

Also known as: Cache-Control, ETag

Where responses are cached

On a second visit to a site, the browser may already have the stylesheet it needs. If the saved response is still usable, the browser can skip the network request entirely. A CDN or caching reverse proxy can also answer from a stored copy. In that case the browser still makes a network request, but the intermediary doesn't have to contact the origin server. A browser cache is private; a CDN cache is shared across users.

How a cache decides what to reuse

Most HTTP caching involves GET responses. A cache looks up a stored response using the request method and URL. If the response includes Vary: Accept-Language, the cache also checks that request header when selecting a stored variant. Requests for different languages should not receive the same cached variant just because their URLs match.

Cache-Control: max-age=60 gives a response a freshness lifetime of 60 seconds. While the saved response is fresh, the cache can normally reuse it without checking upstream. Once it becomes stale, it does not necessarily need to download the whole response again. It can revalidate the copy by sending the saved ETag, a validator for that version of the response, in an If-None-Match request header. Last-Modified and If-Modified-Since provide a timestamp-based alternative.

Example: a product catalog

The first GET /api/catalog returns the catalog body and these headers:

HTTP/1.1 200 OK
Cache-Control: public, max-age=60
ETag: "catalog-v7"

While the cached response is fresh, a later request can use it directly. After it goes stale, the cache can send If-None-Match: "catalog-v7". If that version still matches, the server replies 304 Not Modified with no body, so the cache keeps using the body it already has. If the catalog has changed, the server sends 200 OK with the new body and tag. A 304 saves the response body transfer, not the round trip needed to check the version.

Choosing a cache policy

Give assets with content hashes in their filenames a long freshness lifetime: changing the content gives the asset a new URL. For HTML at a stable URL, no-cache is often a better fit. Despite its name, it allows storage but requires validation before reuse. Use no-store when the response should not be saved by an HTTP cache. For a personalized response that may be stored by the browser but must not be shared, use private, subject to the other caching rules.

What comes up in interviews

You might be asked to set different lifetimes for a CDN and a browser. For a public response, Cache-Control: public, max-age=60, s-maxage=600 makes a stored copy fresh for up to ten minutes in a shared cache but only one minute in a browser cache. These lifetimes are not added together: a browser receiving a cached CDN response accounts for its existing age, reported in the Age header.