TechnologyWeb Performance

How browser and HTTP caching work, from Cache-Control to the disk cache

How browsers decide what to store, when to revalidate, and when to refetch entirely, and how HTTP caching headers control every one of those decisions.

MAMichael Adeyemi — Senior Technology Writer, MSc, Distributed SystemsPublished 2 October 2025Last reviewed 30 January 202611 min readFoundational2,020 words

Fact-checked by Jess Tran, Health & Wellbeing Writer (MPH, Public Health) · 5 primary sources cited · how we review

Engraved illustration of a browser window storing labelled files in a small archive

In short

Browser caching stores a copy of a previously fetched resource locally so a later request can be answered instantly or with a lightweight check, instead of downloading the full response again. Every caching decision is governed by a small set of HTTP response headers that the server controls, chiefly Cache-Control, ETag and Last-Modified. Getting these headers right is usually a bigger performance lever than almost any code-level optimisation, because it removes network round trips entirely rather than making them faster.

Every time a browser loads a page, it must decide, resource by resource, whether it already has a usable copy of that file. That decision is not left to guesswork: it follows explicit instructions the server attached to the response the first time the resource was fetched. Those instructions are what the phrase 'HTTP caching' actually refers to, and they apply identically to a stylesheet, an API response, a font file or an entire HTML document.

The two questions every cache answers

A cache handling a repeat request effectively asks two questions in sequence. First: is my stored copy still considered fresh, meaning it can be used immediately without contacting the server at all? Second, only if the answer to the first is no: is my stored copy still valid, meaning the server confirms nothing has actually changed, even though its freshness window has expired? The answer to the first question comes from Cache-Control's max-age or Expires; the answer to the second comes from validators like ETag and Last-Modified.

Cache-Control: the primary instruction

Cache-Control is a response header the server sets to control exactly how and for how long a response may be reused, and it can combine several directives at once.

Common Cache-Control directives
DirectiveMeaning
max-age=NThe response is considered fresh for N seconds from when it was fetched
no-cacheThe response may be stored, but must be revalidated with the server before each reuse
no-storeThe response must not be stored anywhere, in any cache, under any circumstances
publicThe response may be stored by shared caches (such as a CDN), not just the browser
privateThe response may only be stored by the end user's browser, not by shared intermediaries
immutableThe response will never change during its freshness window, so it never needs revalidation even on reload

A common point of confusion is that no-cache does not mean 'do not cache'; it means 'cache it, but check with the server before reusing it every single time'. The directive that actually prevents storage entirely is no-store, and it is reserved for genuinely sensitive responses that must never persist on disk.

Validators: cheaper than refetching

Once a cached response's freshness window has expired, the browser does not necessarily need to download it again in full. If the server previously supplied an ETag (an opaque fingerprint of the response content) or a Last-Modified date, the browser can send a conditional request containing that value. If the resource has not actually changed, the server replies with a 304 Not Modified status and an empty body, telling the browser to keep using its stored copy and simply refresh its freshness timer.

  • ETag is more precise, since it can detect a content change even when a file's modification timestamp is unreliable or unavailable.
  • Last-Modified is coarser (typically second-level precision) but requires no extra computation to generate, since it is often just a filesystem timestamp.
  • A 304 response typically transfers only a few hundred bytes of headers, versus the full resource body for a fresh 200 response.
  • Both validators can be used together; if present, ETag generally takes precedence over Last-Modified for the actual comparison.

Where cached content actually lives

Browsers maintain more than one caching layer, and they are checked in a fairly predictable order for a typical navigation.

  1. Memory cache: extremely fast, but limited in size and cleared when the tab or browser process closes; used for resources reused within the same page session.
  2. Disk cache: persists across browser restarts and holds the bulk of cached resources, checked when memory cache misses.
  3. Service worker cache (Cache API): under explicit developer control via JavaScript, allowing an application to define custom caching logic, including offline availability, independent of standard HTTP caching rules.
  4. HTTP cache in a shared intermediary such as a CDN or corporate proxy, which sits between the browser and the origin and can serve cached responses to many different users.

A service worker sits in a genuinely different category from the first two: rather than passively obeying Cache-Control headers, it intercepts every network request the page makes and lets developer-written JavaScript decide, request by request, whether to serve from a cache, fetch from the network, or apply a custom strategy such as serving cached content while fetching an update in the background.

The versioned filename pattern

The most reliable way to combine long caching with instant updates is to bake a content hash into the filename of a static asset, for example app.a3f9c1.js, and set an extremely long max-age with the immutable directive on it. Because the filename itself changes whenever the content changes, the browser never needs to ask whether app.a3f9c1.js has changed — it never will, by construction — while a genuinely new version simply arrives under a new filename that was never cached in the first place. The HTML that references the asset is served with little or no caching, so the reference always points to the current filename.

Illustrative repeat-visit load time by caching strategy

Milliseconds for a typical set of static assets, illustrative figures

Figures are illustrative and depend heavily on asset size, connection speed and server response time; they are intended to show the relative ordering of the strategies, not precise real-world values.

Aggressive long-lived caching with hashed filenames

Pros

  • Repeat visits can skip the network entirely for unchanged assets, which is the fastest possible outcome
  • Removes load from the origin server and any intermediary caches for the vast majority of repeat requests
  • Deployment becomes simpler because there is no need to actively purge or invalidate old versions

Cons

  • Requires a build process that generates content-hashed filenames and rewrites references automatically
  • The HTML entry point itself must still be served with careful, usually short, caching to avoid pointing at stale asset filenames
  • Old cached versions can linger indefinitely on a user's device, which is fine for immutable assets but wastes some disk space

Vary and the risk of serving the wrong cached response

A cached response is only useful if it is actually appropriate for the request that reuses it, and the Vary header is what protects against serving the wrong one. Vary tells a cache which request headers must match, in addition to the URL, before a stored response can be reused; a common example is Vary: Accept-Encoding, which prevents a cache from serving a gzip-compressed response to a client that requested an uncompressed one, and Vary: Accept-Language, which stops a cached page in one language being served to a request that asked for another.

Getting Vary wrong causes two opposite failures. Omitting a header that should be included in Vary can cause a cache, particularly a shared one such as a CDN, to serve content intended for one user segment to a different one — a serious defect if the varying content includes anything personalised. Over-including headers in Vary, on the other hand, fragments the cache into so many small variants that the effective hit rate collapses, since a request with a slightly different, functionally irrelevant header value is treated as a completely different resource.

Stale-while-revalidate: serving fast and updating quietly

A more recent Cache-Control extension, stale-while-revalidate, addresses a common tension: strict freshness windows force occasional slow requests when the window expires, while long freshness windows risk serving outdated content. The directive lets a cache serve a stale response immediately while it fetches a fresh copy in the background for next time, within a bounded grace period after the normal freshness window ends.

stale-while-revalidate compared with a plain max-age
BehaviourPlain max-age onlymax-age with stale-while-revalidate
Request within freshness windowServed instantly from cacheServed instantly from cache
Request just after window expiresWaits for a full network round tripServed instantly from the stale copy; refresh happens in the background
Request well past the grace periodWaits for a full network round tripWaits for a full network round trip

This pattern suits content that changes periodically but where a few extra seconds of staleness is an acceptable trade for consistently fast responses, such as a news index page or a product listing. It is less appropriate for content where even a brief window of staleness would be actively misleading, such as a live stock price or account balance.

Debugging a caching problem in the browser

A browser's network inspector panel reports, for each request, whether the response came from the memory cache, the disk cache, a service worker, or the network, along with the full set of response headers that produced that outcome. Working through a caching problem is usually faster starting from this panel than from guessing at server configuration, since it shows what the browser actually did rather than what the headers were intended to achieve.

  1. Check the request's status and size column: a 200 status with a tiny transferred size and a cache label indicates it was served from a local cache rather than the network.
  2. Inspect the response headers for Cache-Control, ETag and Last-Modified to see exactly what freshness and validation rules were in force.
  3. Disable the cache temporarily in developer tools to confirm whether an apparent bug disappears, which isolates a caching issue from a genuine application bug.
  4. For service-worker-related problems, inspect registered service workers and their associated Cache Storage entries directly in the application panel, since these are invisible to the ordinary network cache view.

Key points

  • Caching decisions are governed by response headers the server sets, chiefly Cache-Control, ETag and Last-Modified.
  • no-cache means always revalidate before reuse; no-store means never store the response at all.
  • A 304 Not Modified response lets a browser confirm a cached copy is still valid without re-downloading it.
  • Hashed, versioned filenames combined with long max-age values give the best of both long caching and instant updates.
  • Service workers intercept requests under explicit developer control and are not bound by standard HTTP caching rules.

Sponsored video

Advertisement

Checking for a video ad…

Frequently asked questions

Sources

About the author

Michael Adeyemi — Senior Technology Writer

Michael writes Inquro's computing and web-infrastructure coverage. He worked for eight years as a platform engineer on high-traffic content systems before moving into full-time technical explanation, and he still prototypes every measurement described in his articles before publishing the numbers.

Qualifications
  • MSc, Distributed Systems — University of Manchester
  • BEng, Computer Engineering — University of Lagos
Experience
  • Eight years as a platform engineer on high-traffic content delivery systems
  • Four years writing standards-based technical documentation
Subject areas:
Web performance, Networking, Systems architecture

Reviewed for factual accuracy by Jess Tran, Health & Wellbeing Writer (MPH, Public Health), on 30 January 2026.

Whether health claims stay descriptive rather than prescriptive, and whether study limitations are visible in the body text.

Inquro articles are commissioned, sourced, reviewed and re-checked under a published editorial policy. Corrections are made in place and dated — write to editorial@inquro.example if you find an error.

Related explainers

More from Technology and connected clusters across the full library.

TechnologyWeb Performance

Core Web Vitals explained: what LCP, INP and CLS actually measure

A practitioner's guide to Core Web Vitals: what Largest Contentful Paint, Interaction to Next Paint and Cumulative Layout Shift measure, how field data differs from lab data, and how to diagnose each metric.

Michael AdeyemiUpdated 28 July 202611 min
TechnologyWeb Performance

How the image format you choose changes how heavy a page feels

A comparison of JPEG, PNG, WebP and AVIF covering compression approach, transparency and animation support, and how format choice, responsive sizing and lazy loading together determine a page's real-world weight.

Michael AdeyemiUpdated 2 June 20268 min
TechnologyNetworking

How DNS resolution works, step by step

A complete walkthrough of DNS resolution: the recursive resolver, root, TLD and authoritative servers, caching layers, TTL behaviour, and why DNS is so often the hidden cause of slow first loads.

Michael AdeyemiUpdated 15 July 202611 min
TechnologyNetworking

How the TLS handshake works, from ClientHello to encrypted data

A step-by-step explanation of the TLS 1.3 handshake: key exchange, certificate verification, cipher suites, session resumption and why the number of round trips decides how fast a secure connection feels.

Michael AdeyemiUpdated 28 July 202610 min

Keep reading

Definitions used here

Go deeper