Skip to main content

How to fix: Vary: Cookie on Static Resource

A static asset (image, JS, CSS) is served with Vary: Cookie. This forces shared caches to store a separate copy for each unique cookie value, defeating caching entirely for that asset.

Why it matters

All users fetch the same static file on every request without benefiting from CDN or browser caching, causing unnecessary origin load and slow page loads at scale.

Vary: Cookie instructs caches to key stored copies by Cookie header value. For static assets that do not change per user (CSS, JS, images), this is always wrong: it prevents caching and dramatically increases origin bandwidth usage.

How to fix it

  1. 1Remove Vary: Cookie from static asset responses.
  2. 2Configure the CDN or web server to strip Vary: Cookie for assets at /static/, /_next/static/, /public/ paths.

Code examples

Nginx: static asset cache config

nginx
location ~* \.(js|css|png|jpg|webp|woff2|ico)$ {
  expires 1y;
  add_header Cache-Control "public, immutable";
  # No Vary: Cookie here
}

References

Detected automatically by VulnRadar. The check id is vary-cookie-on-static-resource, stable across every scan so you can filter or diff on it.

See every config check

Questions

How severe is Vary: Cookie on Static Resource?
VulnRadar rates this low severity in the config category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id vary-cookie-on-static-resource, which stays the same between runs so you can filter, diff, or gate CI on it.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for vary: cookie on static resource

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Vary: Cookie on Static Resource | VulnRadar