Why Your Full-Page Cache Needs an Opinion About Query Strings
Two different incidents on the same WordPress VIP-style multisite network, months apart, turned out to share one root cause. The first was a bot sending Accept: application/json to an ordinary HTML page, silently tripping a content-negotiation guard and getting served an ads-stripped page — which then got written into the full-page cache under the URL's normal key and handed to every real visitor…
Two separate incidents on the same WordPress VIP-style multisite network, months apart, both traced back to a single root cause: a full-page cache key that let the request decide what it meant rather than being designed purposefully. The first incident involved a bot sending Accept: application/json to an HTML page, which triggered a content-negotiation guard and resulted in an ads-stripped page getting cached under the normal URL.
The second incident saw a crawler re-fetching URLs with tracking parameters, each unique value creating its own cache entry, leading to expensive origin renders for URLs that would never be requested again.
The key issue is that a cache key should not be determined by whatever the request contains, but rather be explicitly designed to account for what actually varies the response. A default cache key based solely on the request URL (path plus query string) often assumes that every distinct URL-query string combination yields a different response, which is rarely true. Factors like headers and cookies can influence the rendered response without affecting the underlying URL.
To fix this, known tracking parameters should be stripped from the cache key at the edge/CDN layer before it becomes the key, and any headers that genuinely affect the response should be explicitly varied on. This prevents the cache from serving different cached copies to different users based on request headers or parameters that don't actually change the content.
The solution must be applied uniformly across the system, not patched individually for each site, as incidents can affect multiple sites with similar configurations.
In essence, a well-defined cache key should only include factors that truly determine the response. Query strings are a major source of false cache misses for sites with tracking parameters, so they should be explicitly excluded from the key. Application logic headers that affect the response need to have an explicit Vary directive, or the logic must be changed to stop relying on headers that aren't reliable for caching purposes.
By applying this cache key design principle cluster-wide, similar cache-related issues can be avoided.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to