Why a 'Fresh' Local Cache Can Still Trigger a Redundant 5MB Download
A simple mismatch in request headers can cause browsers to bypass a perfectly fresh cached asset, forcing a slow and expensive network request.

When developers configure HTTP caching, they often rely on the max-age directive to keep assets loading instantly from the local disk. Under standard behavior, a stored HTTP response is considered fresh if its calculated age is less than the duration specified by this directive, meaning the browser can serve it directly without hitting the network. However, this assumption falls apart when content negotiation enters the picture, leading to unexpected and heavy network requests for assets that should already be stored locally.
By default, browser caches distinguish responses from one another essentially based on their URLs. If a resource lives at a specific URL, the browser expects to find and reuse it. But content negotiation allows a server to return different versions of a resource at that same URL depending on the client's request headers. To manage this, servers use the Vary header. This header tells the browser that the response is keyed on a composite of the response URL and the specified request headers, rather than just the URL alone.
How the Vary Header Alters Cache Matching
When a server sends a response with a Vary header, it instructs the browser's cache-matching algorithm to be highly specific. Instead of looking up a resource solely by its URL, the browser must verify that the incoming request's headers match the headers of the cached request. If there is any discrepancy in these specified headers, the browser treats the cached asset as a mismatch, even if the asset is completely fresh according to its max-age.
Consider a hypothetical scenario where a web application caches a large 5MB localized product catalog. The server sends this catalog with the response header "Vary: Accept-Language, Safe-Ports". This tells the browser to cache different versions of the catalog depending on the user's language and a custom security port header. Later, while the user navigates the site, a third-party analytics script triggers a fetch request for that exact same catalog URL. However, this script strips the custom "Safe-Ports" header from its request metadata. Even though the 5MB catalog is sitting in the local cache with 23 hours of freshness remaining, the browser's cache-key lookup fails the strict Vary match because of the missing header. As a result, the browser bypasses the local copy and initiates a redundant, slow 5MB download over the user's cellular connection.
Key Takeaways for Developers
- Be precise with the Vary header by only including headers that actually alter the response content.
- Audit third-party scripts to ensure that secondary fetch requests maintain the same header structure as primary page requests.
- Monitor cellular data impacts since unintended cache misses on large files directly degrade performance and increase data costs for mobile users.
Your reaction
Loading reactions…


Comments 0
Review comments