RealComposer
Performance & Edge

HTTP Vary Header

Direct Definition

The HTTP Vary response header lists request headers that must participate in the cache key because they change the response body. For APIs, common examples include Accept-Encoding, Accept-Language, and sometimes Authorization when responses are user-specific but still edge-cacheable per user.

Technical Architecture & Deep-Dive

Omitting Vary when content negotiates by header can cause caches to serve the wrong representation, such as gzip to a client that cannot decode it, or English JSON to a French client. Setting Vary too broadly fragments the cache and destroys hit ratio.

Edge gateways should set Vary deliberately on transformed responses, normalize encodings at the edge when possible, and prefer separate URLs or cache keys for major variants instead of listing every custom header. For public JSON, Vary often includes only Accept-Encoding.

Key Architectural Benefits

Prevents cross-client cache poisoning on negotiated responses.
Documents which headers must be part of CDN cache keys.
Balances correctness against cache fragmentation on API routes.

Vary for Compressed JSON APIs

http
Vary: Accept-Encoding
Cache-Control: public, max-age=60, s-maxage=300
REALCOMPOSER EDGE WORKSPACE

Implement HTTP Vary Header at the Edge

Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.

START BUILDING FREE

Frequently Asked Questions

Q:Should Vary include Authorization?

Only when shared caches store per-user responses and your cache key already isolates users safely. Many personalized APIs should use private or no-store instead.

Related Architecture Concepts

Ready-to-Use Edge Recipes