Browser caching stores copies of web files so they can be reused without downloading them on every request. This can make a site faster, but it can also make a browser show an older CSS file, JavaScript file, image, or HTML document after an update.
The main response headers that control this behaviour are Cache-Control, ETag, and Expires. They control different parts of caching: how long a response may be reused, how a browser checks whether it changed, and when a cached response becomes stale.
Table of Contents
How browser caching works
When a browser requests a file, the server can return the file together with caching headers. The browser stores the response and follows those headers on later visits.
While the cached response is fresh, the browser can use it without contacting the server. This is the main reason an updated file may not appear immediately. The browser is following the previous caching instructions, not necessarily ignoring the update.
When the response becomes stale, the browser can contact the server to revalidate it. Revalidation checks whether the cached copy is still current. If it is unchanged, the server can confirm that the browser may keep using its copy. If it changed, the server sends the new response.
Cache-Control: the main caching policy
Cache-Control is the most flexible header in this comparison. It can set a freshness period and define whether a response may be stored or must be checked again.
max-age=3600allows a cached response to be reused for 3,600 seconds, or one hour, before it becomes stale.no-cacheallows storage but requires a check with the server before reuse.no-storetells the browser not to store the response.must-revalidaterequires a stale response to be checked before it is reused.
These directives have different effects. no-cache does not mean “do not save.” It means “do not use the saved response without revalidation.” no-store is the directive for content that should not be stored.
Example: a long-lived versioned asset
Cache-Control: public, max-age=31536000, immutableThis type of policy is suitable for a static asset when its URL changes whenever its contents change. For example, a site can load app.abc123.js and later publish app.def456.js. The old URL can remain cached because the new version uses a different URL.
Example: an HTML document that should be checked
Cache-Control: no-cacheThis allows the browser to keep a copy while requiring revalidation before it uses that copy. It is useful when the HTML may change and the document contains links to current CSS or JavaScript files.
ETag: checking whether a file changed
An ETag is an identifier for a particular version of a response. The browser saves the value with the cached response. During revalidation, it sends that value back to the server in an If-None-Match request header.
If the server determines that the cached version is still current, it can return 304 Not Modified without sending the full file again. The browser then uses its stored copy. If the identifier no longer matches, the server returns the updated response.
ETag: "asset-v2"ETag validation reduces the amount of data transferred, but it does not decide when the browser must revalidate. A freshness rule such as max-age or no-cache controls that timing.
Expires: an older freshness rule
Expires sets a fixed date and time after which a cached response is considered stale.
Expires: Wed, 30 Dec 2026 12:00:00 GMTUnlike Cache-Control: max-age, which uses a relative number of seconds, Expires uses an absolute date. Clock differences can make absolute dates less reliable, so modern configurations normally use Cache-Control as the primary policy.
When both headers are present, a browser generally uses the more specific Cache-Control freshness rule instead of the older Expires rule. Keeping both may support older clients, but their values should not conflict.
Cache-Control, ETag, and Expires compared
| Mechanism | What it controls | Typical use |
|---|---|---|
| Cache-Control | Freshness, storage, and revalidation rules | Primary policy for most responses |
| ETag | Whether a stored response matches the current server version | Efficient revalidation |
| Expires | The date and time when a response becomes stale | Legacy or compatibility support |
These mechanisms are not alternatives that must be used alone. A response can use Cache-Control to set its freshness policy and an ETag to support efficient revalidation. Expires can be added when compatibility with older behaviour is needed.
Choosing a policy for different content
Static assets
CSS, JavaScript, images, and font files can use a long freshness period when their URLs are versioned. Change the filename or query string when the content changes, then reference the new URL in the HTML.
styles.v3.css
styles.v4.cssThis approach is called cache busting. It prevents a browser from treating a changed file as the same resource at the old URL.
HTML documents
HTML often controls which assets a visitor loads, so it usually needs a shorter freshness period or revalidation. A no-cache policy can keep the response stored while checking for updates before reuse.
Frequently changing content
For content that changes often, use a policy that requires regular revalidation. Use no-store when the response must not be stored at all. Use ETag when storing a response is allowed and returning a compact “not changed” response is useful.
Preventing stale update problems
- Use long cache times only for files whose URLs change when their contents change.
- Use
no-cacheor a shortmax-agefor HTML that must reflect recent changes. - Keep the ETag current when the response content changes.
- Do not reuse an old asset URL for new file contents when that URL has a long cache lifetime.
- When using both
Cache-ControlandExpires, set values that describe the same freshness period.
A browser may continue to show an older file until its freshness period ends, until it revalidates the response, or until the page references a new cache-busted URL. That behaviour is normal when the previous response allowed the browser to reuse its stored copy.