Performance and accessibility 4 min read Updated
How HTTP caching decides what is reused
In short
Caching is safe to use when each response carries an explicit Cache-Control header that matches how often its content changes.
A returning visitor should not have to download the same files again. Caching can prevent that, but only when the server says what the browser may keep, and response headers decide it. Set an explicit Cache-Control header on every response first, rather than leave the decision to the browser’s heuristics.
A fresh response is reused without asking
A stored response is either fresh or stale. A fresh response can be reused without asking the server. A stale response has expired and has to be checked. Age decides, meaning the time since the response was generated. A response with a max-age of one week is fresh for the first week and stale after it. When Expires and max-age are both present, max-age takes precedence.
A response without a Cache-Control header can still be stored and reused under heuristic caching. MDN describes this as a workaround from before Cache-Control was widely adopted, and says that basically all responses should set Cache-Control explicitly. Relying on heuristics is therefore a weak choice.
Which Cache-Control directives matter
| Directive | What it does | Typical use |
|---|---|---|
| max-age | Marks the response fresh for a set number of seconds | Versioned static files |
| no-cache | Allows storage, but forces a check with the server before each reuse | HTML and default headers |
| no-store | Prevents the response from being stored at all | Content that must never be kept |
| private | Allows only the browser to store the response | Personalised responses |
| immutable | Means revalidation is not needed while the content is fresh | Versioned files whose content never changes |
The most common mistake is to reach for no-store. It is not recommended as a blanket rule, because you lose benefits such as the back and forward cache. For personalised content, the recommendation is no-cache combined with private. no-store also does not delete a response that is already stored for the same URL. The web.dev guide notes that some browsers ignore immutable, so treat it as an optimisation rather than a guarantee.
Working on something similar in your own product? A few honest sentences are enough – we read every enquiry and reply by email. Apply with your idea
A stale response can still be validated
A stale response is not discarded at once. The browser can send a conditional request, using If-None-Match with the ETag value or If-Modified-Since with the Last-Modified date. If the resource has not changed, the server answers 304 Not Modified, and the stored copy becomes fresh again. If it has changed, the server sends the latest version with 200 OK.
web.dev recommends ETag because it is more accurate. An ETag is typically a hash or another fingerprint of the content. Last-Modified uses a time format that is complex to parse, and distributed servers struggle to keep file update times in step. MDN adds that RFC 9110 recommends sending both headers, and that If-None-Match takes precedence when both are present.
Long caching for versioned files, a different rule for HTML
Static files whose names change with their content can be cached for a long time. web.dev suggests a max-age of 31536000 seconds, which is one year, for versioned assets. MDN pairs such long-lived assets with the immutable directive. When the content changes, the file name changes too, so an old copy is never reused by mistake. Self-hosted font files are a common example, as the article Web fonts without slowing the page or moving the text explains.
HTML is different. Its address usually stays the same while its content changes, so it needs a different rule. MDN says no-cache, rather than no-store, is appropriate for main resources such as HTML, because the aim is to keep HTML up to date, not to forbid storage. That is why recommended default headers often include no-cache. Caching is only one lever for speed. The other causes are covered in fixing Largest Contentful Paint.
Browsers and CDNs can handle headers differently. Test each deployment rather than trust one header.
A practical checklist
- Check the Cache-Control header of each type of file in the browser’s network panel, not only the main page.
- Set an explicit Cache-Control header on every response, so that heuristic caching does not decide for you.
- Put a content fingerprint into the file names of static assets, and serve them with a long max-age.
- Use no-cache for HTML and for pages that must stay current, and reserve no-store for content that must never be kept.
- Send an ETag with responses, so that unchanged files return 304 Not Modified.
- Test with a reload and with the Back button, because MDN notes that no-cache does not guarantee revalidation for history navigation.
Common questions
- What is the difference between no-cache and no-store?
- no-cache lets the browser store a response but makes it check with the server before each reuse. no-store stops the response being stored at all, and web.dev says it also tells intermediate caches such as CDNs never to store it.
- Should HTML be cached for a long time?
- Usually not. MDN recommends no-cache for HTML, so that the browser checks for updates and the page stays current.
- Why does the Back button sometimes show an old page?
- MDN notes that no-cache, and its equivalents, do not guarantee revalidation for history navigation such as the Back button. Test that case separately from normal reloads.
Sources
- HTTP caching - HTTP | MDN, MDN Web Docs. Accessed 24 November 2026
- Prevent unnecessary network requests with the HTTP Cache, web.dev. Accessed 24 November 2026
Further reading
-
Web fonts without slowing the page or moving the text
Ship one compressed, subsetted file per style you need, and pick a font-display value for each family on purpose.
-
Responsive images that fit the screen and the layout
Send each screen a file that matches the space the image occupies, and declare its dimensions so the layout holds while it loads.
-
CDN edge caching: Vary, cookies and safe purging
An unconfigured CDN either misses HTML and XML sitemaps completely or accidentally caches another user’s session cookie. Understand cache keys, Vary headers and targeted purging before turning on edge caching.
Have an idea that should exist? Or a working product that needs more customers, a new website or a complete rework? Bring us anything. Apply with your idea