Vary Header Explained

What the HTTP Vary header does and when it's used.

Published October 17, 2026

Vary lists request headers that affect the response, so caches store separate versions per header value (for example Accept-Encoding or Origin).

How it works

Without it, a cache may serve the wrong variant.

The Vary header is part of the HTTP message and is case-insensitive in name.

In a real exchange

curl -i https://example.com/
Vary: Accept-Encoding, Origin
Where Vary appears.

Practical examples

The header

Vary: Accept-Encoding, Origin

Set or use it in code

add_header Vary "Accept-Encoding";

Inspect it

curl -sI https://example.com | grep -i 'vary'

Common mistakes

  • Omitting Vary with content negotiation
  • Varying on User-Agent and destroying cache hit rates
  • Using Vary: * unnecessarily

Key takeaways

  • Vary: Vary lists request headers that affect the response, so caches store separate versions per header value (for example Accept-Encoding or Origin).
  • Check it in browser DevTools → Network.
  • Test with curl -I before deploying.

FAQ

Why does Vary matter for CDNs?

It stops them mixing responses meant for different requests.

Is Vary case sensitive?

Header names are case-insensitive; values may not be.

More HTTP articles