Test No-Vary-Search Query-String Caching Before a Release

Run a local experiment to evaluate No-Vary-Search query parameters caching, compare cache layers, and identify unsafe parameters before release.

Published
Reading time
8 min read
Test No-Vary-Search Query-String Caching Before a Release
On this page

No-Vary-Search can tell a compatible cache that selected query parameters do not distinguish one reusable response from another. Before relying on it for a performance release, test the actual browser and cache path: two URLs that look equivalent to your application are not necessarily treated as equivalent by every cache.

This experiment uses a local server and URLs that differ in tracking-like parameters. It also includes a control parameter that must remain significant. The example has not been executed here, and current browser support and implementation details could not be verified against official browser documentation in this run. Verify those details for your target browser versions before publishing or deploying a conclusion.

Key Takeaways

  • No-Vary-Search: params=("utm_source" "utm_medium") expresses that the named parameters can be ignored when matching a response for reuse. Other query parameters remain significant.
  • Browser behavior is implementation-dependent. A browser may support the header only in particular caching or prefetch scenarios; do not assume it changes every navigation cache lookup.
  • A browser response header does not configure a CDN's cache key. Test and configure the browser, CDN, and origin as separate layers.
  • Ignore a parameter only when changing or removing it cannot change the response's content, access rules, or user-specific data.
  • Record the browser version, actual response headers, request sequence, and observed network activity. This article provides a reporting template, not claimed results.

What No-Vary-Search changes

A cache normally needs to decide whether a stored response is suitable for a new request. Query strings are part of the URL, so these requests may otherwise be treated as distinct:

/asset?color=blue&utm_source=one
/asset?color=blue&utm_source=two

In this example, the response header below identifies utm_source and utm_medium as parameters that do not need to distinguish reusable responses:

No-Vary-Search: params=("utm_source" "utm_medium")

That does not mean every request for /asset is equivalent. A request with color=red differs in a parameter not named in the header, so the header does not declare it equivalent to color=blue.

The header is a declaration about response equivalence, not permission to cache a response that is otherwise uncacheable. Ordinary cache controls, freshness, request context, and the implementation's supported behavior still matter. It is also distinct from the HTTP Vary header, which concerns selected request headers rather than declaring query parameters irrelevant.

Advertisement

Run a local comparison

The following lab uses Python's standard library and binds only to the local machine. It serves a constant test response at /asset; the query parameters are used to exercise cache matching, not to generate page content. Use a browser profile without extensions that could alter requests, and keep its developer tools' cache-disabling option off.

Save this as no_vary_lab.py:

import argparse
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import urlsplit

parser = argparse.ArgumentParser()
parser.add_argument("--no-vary-search", choices=("on", "off"), default="on")
args = parser.parse_args()

INDEX = b"""<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Cache matching lab</title></head>
<body>
  <h1>Cache matching lab</h1>
  <p>Click a link, then return here using Back.</p>
  <ul>
    <li><a href="/asset?color=blue&amp;utm_source=one">A: blue, source one</a></li>
    <li><a href="/asset?color=blue&amp;utm_source=two">B: blue, source two</a></li>
    <li><a href="/asset?color=red&amp;utm_source=one">C: red, source one</a></li>
  </ul>
</body>
</html>"""

ASSET = b"""<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Lab asset</title></head>
<body><h1>Constant lab response</h1></body>
</html>"""


class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        path = urlsplit(self.path).path
        if path == "/":
            body = INDEX
            cache_control = "no-store"
        elif path == "/asset":
            print(f"ORIGIN GET {self.path}", flush=True)
            body = ASSET
            cache_control = "public, max-age=600"
        else:
            self.send_error(404)
            return

        self.send_response(200)
        self.send_header("Content-Type", "text/html; charset=utf-8")
        self.send_header("Content-Length", str(len(body)))
        self.send_header("Cache-Control", cache_control)
        if path == "/asset" and args.no_vary_search == "on":
            self.send_header(
                "No-Vary-Search", 'params=("utm_source" "utm_medium")'
            )
        self.end_headers()
        self.wfile.write(body)


server = ThreadingHTTPServer(("127.0.0.1", 8000), Handler)
print(f"Lab running; No-Vary-Search={args.no_vary_search}", flush=True)
try:
    server.serve_forever()
except KeyboardInterrupt:
    pass
finally:
    server.server_close()

Run it with the header enabled:

python3 no_vary_lab.py --no-vary-search on

Open http://127.0.0.1:8000/ in the browser being evaluated. In developer tools, preserve the network log if that option is available. Clear this lab's cached data before each run, and verify that the cache is not disabled by developer tools.

  1. Click A to populate a candidate response. In the network panel, inspect its actual response headers and confirm that both Cache-Control and No-Vary-Search arrived.
  2. Return to the index with Back, then click A again. This exact-URL check helps establish whether the browser can reuse the response in this setup. Record both the network panel and the server terminal; do not infer a cache hit solely from a fast load.
  3. Return to the index and click B. It changes only the ignored utm_source value. Record whether the browser sends a new /asset request to the local server and what the network panel reports.
  4. Return to the index and click C. It changes color, which is not listed as ignored. Record whether it generates a separate request or is otherwise handled as a distinct cache entry.
  5. Stop the server with Ctrl+C. Restart with python3 no_vary_lab.py --no-vary-search off, clear the lab's cached data, and repeat the same sequence as a control.

The local server logs each /asset request that reaches it. The browser's network panel adds context about cache use and request handling. Because the lab has no CDN or service worker, a missing server log is useful evidence of local reuse, but inspect the browser's recorded request details too. A request reaching the server shows that this particular navigation did not avoid an origin request; it does not by itself establish which cache decision caused that result.

The response body is deliberately identical for A, B, and C. Do not use the displayed text to decide whether a cache hit occurred. In particular, C exists to check URL matching, not to demonstrate that the server renders different colors.

Record the result instead of assuming it

Fill in a report for every browser and test environment you use:

  • Browser and exact version: Not tested here; record yours.
  • Operating system and relevant browser settings: Not tested here; record yours.
  • Actual A response headers: Not observed here; copy the relevant headers from developer tools, including cache directives and No-Vary-Search.
  • A repeated, B, and C: Not observed here; record network-panel indications and whether each request reached the server, with the header both on and off.
  • Conclusion: State only what the recorded sequence demonstrates for that browser and scenario. Note ambiguous results and repeat the run if needed.

This experiment exercises ordinary link navigations. It does not establish behavior for prefetching, prerendering, other browser versions, or a deployed CDN. If the product depends on one of those paths, reproduce that path separately and consult the target browser's current official documentation. A miss can reflect unsupported behavior, a different cache path, eviction, partitioning, settings, or another condition; it is not sufficient on its own to prove lack of support.

Advertisement

Separate browser, CDN, and origin behavior

The local lab removes the CDN so that browser behavior is easier to inspect. A production request can involve several independent decisions:

  • Browser: Determines whether its implementation can reuse a stored response in the relevant context. Inspect the delivered headers and browser network activity.
  • CDN or reverse proxy: Uses its own cache-key and caching configuration. Confirm whether it preserves the header, how it keys query strings, and whether any provider-specific feature interprets the header. Do not assume either that it ignores the header or that it honors it.
  • Origin: Generates the response and cache headers. Ensure the origin's response is genuinely equivalent for requests that a cache may group together.

For a deployed test, use an authorized test environment, request known URL variants, and correlate browser activity with CDN cache diagnostics and origin logs. A browser cache hit may prevent a request from reaching the CDN at all; a CDN hit may prevent it from reaching the origin. Check each layer independently, and clear or isolate relevant caches between controlled runs. Configuration changes do not necessarily remove responses already stored under an earlier policy.

Decide which parameters are safe to ignore

Treat an ignored parameter as an equivalence promise: for requests that could share a cache entry, changing or removing it must not alter the reusable response or its authorization requirements.

Tracking parameters can be candidates, but their names alone do not make them safe. Audit application logic, middleware, redirects, response headers, and downstream services. For example:

  • A campaign parameter that selects different HTML or a redirect is not safe to ignore for that response.
  • A parameter that controls access, identifies an account, or selects user-specific data must not be grouped merely to improve cache reuse.
  • A locale, pagination, search, or feature parameter may change the representation even when the route is the same.
  • Duplicate parameters, missing versus empty values, and parameter order can have application-specific meaning. Include the forms your application accepts in its tests.

Also assess the complete caching policy. User-specific or access-controlled responses require appropriate cache directives and access controls; query-key normalization alone cannot make them safe to share. A mistake can expose one user's content to another or serve the wrong page.

Common Mistakes

  • Calling a fast response a cache hit. Use network diagnostics and server-side evidence, not timing alone.
  • Testing only the ignored parameter. Include an exact-URL control and a parameter that must remain significant.
  • Assuming a browser result proves CDN behavior. Test each cache layer and the actual production request path.
  • Treating a single miss as a compatibility verdict. Check the browser version, caching context, settings, and documentation; then repeat a controlled test.
  • Ignoring sensitive parameters. A cache-key change can cross content or authorization boundaries even if it appears to improve reuse.

Best Practices

Start with a small, documented allowlist of parameters proven irrelevant for a specific response. Review that assumption when application behavior changes. Keep a reproducible test matrix for target browser versions and deployment environments, and repeat it after changes to cache headers, CDN rules, redirects, or rendering logic.

Conclusion

Use No-Vary-Search as a response-equivalence declaration, not as a universal caching switch. Measure the exact browser scenario and each deployed cache layer, and ship only after confirming that ignored parameters cannot change content or access.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.