The Vary HTTP header is one of those technical SEO factors that most practitioners treat as a caching concern, not an SEO concern—and that’s a mistake. How you configure Vary affects which version of your content search engines index, how efficiently your CDN serves cached responses, and in mobile-first indexing environments, whether Google is even seeing the right version of your pages. This guide covers the Vary header from a dual perspective: caching efficiency and crawl/indexing impact.
What the Vary Header Actually Does
The Vary header tells intermediate caches—CDNs, proxy servers, browser caches—which request headers to consider when determining whether a cached response can be used. When a server responds with Vary: Accept-Encoding, it signals that the response content varies based on the client’s Accept-Encoding header. A Gzip-compressed response and an uncompressed response should be cached separately because they’re different content for different clients.
The Cache Key Problem
By default, caches use only the URL as the cache key. The Vary header extends the cache key to include specified request headers. This has direct performance and indexing implications: a page served to a mobile browser and a desktop browser might be completely different if you’re using server-side adaptive serving. Without Vary: User-Agent, a CDN could serve the mobile response to a desktop user (or vice versa) from cache, producing a completely wrong page experience.
Common Vary Header Values
The most frequently used Vary values in production:
Vary: Accept-Encoding— Separate cache for Gzip/Brotli vs. uncompressed responsesVary: User-Agent— Separate cache for different client types (use with extreme caution)Vary: Accept-Language— Separate cache for different language preferencesVary: Cookie— Separate cache per cookie value (effectively disables caching)Vary: Accept— Content negotiation for different response formats
The SEO Problem with Vary: User-Agent
This is where technical SEO gets interesting. If your site uses server-side mobile detection and responsive serving (not responsive design, but different HTML based on User-Agent), you face a critical trade-off with Vary: User-Agent.
Google’s Position on Vary: User-Agent
Google has explicitly recommended avoiding Vary: User-Agent for mobile serving. Their reasoning: Googlebot doesn’t send standard mobile User-Agent strings for all crawls, CDN caching with Vary: User-Agent creates massive cache fragmentation, and the operational complexity of dynamic serving is high with many failure modes. Google instead recommends responsive web design (same HTML, different CSS via media queries) or separate mobile URLs with proper canonicalization and rel-alternate markup. If you’re using dynamic serving and must implement Vary: User-Agent, ensure both mobile Googlebot and desktop Googlebot can access the correct version of each page.
Cache Fragmentation: The Performance Tax
User-Agent strings are notoriously diverse. There are thousands of distinct User-Agent strings in active use across real browsers, bots, and tools. Implementing Vary: User-Agent means your CDN creates separate cache entries for every distinct User-Agent string—which is effectively infinite. This destroys cache hit rates, increases origin server load dramatically, and can cause CDN storage costs to spike. The performance penalty is severe enough that most major CDNs either normalize User-Agent before using it as a Vary key or warn against its use entirely.
Vary: Accept-Encoding and SEO
Unlike Vary: User-Agent, Vary: Accept-Encoding is generally well-handled and SEO-safe. Googlebot supports Gzip and Brotli compression and will correctly receive compressed responses. CDNs handle Accept-Encoding variation efficiently because the practical cache key variations are small (compressed vs. uncompressed, Gzip vs. Brotli).
Best Practice Implementation
For virtually all sites, the correct Vary implementation for compression is:
Vary: Accept-Encoding
Applied at the CDN or web server level. This is handled automatically by most modern web servers (Nginx, Apache, Caddy) when compression is enabled. For Nginx, verify your configuration includes proper Vary handling in your gzip or brotli module configuration.
Brotli and Vary Interactions
When serving both Gzip and Brotli, your Vary header should still be Vary: Accept-Encoding—the same header. The cache differentiates based on the actual Accept-Encoding request value. What matters for SEO is that Googlebot receives compressed content correctly. Per Google’s documentation, Googlebot fetches pages with Accept-Encoding: gzip, br in the request, so both formats are supported and should be served when appropriate.
Vary: Accept-Language: Internationalization Implications
For multilingual sites using server-side language detection and serving different content based on Accept-Language headers, Vary: Accept-Language becomes relevant. But this approach has significant crawl and indexing complications.
Why Googlebot May Not See Your International Content
Googlebot crawls from various geographic locations and doesn’t reliably send language preference headers that match your target content. If your site dynamically serves French content to requests with Accept-Language: fr and English to all others, Googlebot may only index your English content regardless of where it crawls from. The proper internationalization implementation for SEO is: separate URLs for each language variant (either subdirectories, subdomains, or ccTLDs), hreflang annotations linking the variants, and canonicalization pointing each language URL to itself.
Content Negotiation vs. Separate URLs
Content negotiation (serving different content on the same URL based on headers) is elegant from a technical standpoint but creates SEO headaches. Google’s Search Console cannot report on different content variants at the same URL. You can’t track rankings for specific language versions. Links pointing to the URL benefit all variants equally, which can dilute rather than concentrate authority. Separate URLs avoid all these issues. Use content negotiation for API responses, not for crawlable HTML pages you want indexed.
CDN Behavior and the Vary Header
Different CDN providers handle the Vary header very differently, and getting this wrong causes both performance and indexing problems.
Cloudflare
Cloudflare largely ignores Vary: User-Agent and Vary: Cookie by default, treating them as effectively not set for caching purposes. This means if you’re relying on Vary: User-Agent to serve different content to mobile vs. desktop users via Cloudflare, it won’t work as expected—Cloudflare will serve the same cached response regardless. Cloudflare does respect Vary: Accept-Encoding and handles compression variation correctly. For mobile serving via Cloudflare, use responsive design or Cloudflare’s own mobile redirect/transform rules.
AWS CloudFront
CloudFront uses cache behaviors and cache policies that explicitly list which headers are forwarded and included in cache keys. The Vary header from origin responses is respected more granularly. For Accept-Encoding, CloudFront has automatic compression with Gzip and Brotli that doesn’t require manual Vary configuration—it handles cache differentiation internally. Configure a cache policy that includes Accept-Encoding if you’re handling compression at the origin rather than at CloudFront.
Fastly and Varnish-Based CDNs
Fastly, built on Varnish, provides fine-grained control over cache key construction via VCL (Varnish Configuration Language). You can normalize User-Agent strings to a small set of variants (mobile/tablet/desktop) rather than using raw User-Agent, dramatically reducing cache fragmentation while still supporting adaptive serving. This is the most performance-efficient approach if you must use dynamic serving.
Diagnosing Vary Header Problems
When something is wrong with your Vary configuration, the symptoms can look like content rendering issues, crawl problems, or performance degradation that’s hard to attribute. Here’s how to audit your current state.
Curl-Based Header Inspection
The fastest way to see your actual Vary headers:
curl -I -H "Accept-Encoding: gzip" https://yourdomain.com/page/
curl -I -H "User-Agent: Googlebot/2.1 (+http://www.google.com/bot.html)" https://yourdomain.com/page/
Compare the response headers (particularly Vary, Content-Type, and Content-Length) for different request configurations. If you see Vary: User-Agent, Cookie, that’s almost always a misconfiguration.
Google Search Console Coverage Analysis
If Vary misconfiguration is causing indexing problems, you’ll typically see: pages discovered but not indexed, pages with “Crawled – currently not indexed” status persisting despite good content, or inconsistent mobile vs. desktop rendering in the Mobile Usability report. Run a URL inspection on affected pages and compare Googlebot’s fetched version with the user version.
Log File Analysis for Vary-Related Crawl Waste
Parse your server logs to identify if Googlebot is making repeated requests for the same URLs with different User-Agent strings. Unusual crawl patterns on the same URL can indicate Vary-driven cache misses are causing origin server hits for every Googlebot request. Tools like GoAccess, Screaming Frog Log Analyzer, or Semrush’s Log File Analyzer can surface this pattern.
Implementation Checklist: Vary Header SEO Best Practices
Based on current Google documentation, CDN behavior, and production implementation experience, here’s the complete technical checklist:
For Responsive Design Sites (Recommended Architecture)
- ✅ Serve
Vary: Accept-Encoding(handled by web server automatically with compression enabled) - ✅ No
Vary: User-Agent— all devices receive same HTML - ✅ Single canonical URL per piece of content
- ✅ Verify Googlebot sees correct content via URL Inspection
For Dynamic Serving Sites (Legacy Architecture)
- ⚠️ Implement
Vary: User-Agentat origin but test CDN behavior - ⚠️ Consider normalizing User-Agent at CDN layer to reduce fragmentation
- ✅ Verify both Smartphone Googlebot and Desktop Googlebot receive correct content versions
- ✅ Use Google Search Console’s mobile usability testing to confirm
- ⚠️ Monitor CDN hit rates closely — User-Agent variation tanks cache efficiency
For Multilingual Sites
- ✅ Use separate URLs per language, not content negotiation
- ✅ Implement hreflang correctly on all language variants
- ❌ Avoid
Vary: Accept-Languageon pages you want Googlebot to index correctly
Technical SEO Problems Hiding in Your Server Configuration?
Vary header misconfiguration, crawl waste, and caching problems are often invisible until they’ve already cost you rankings. Our technical SEO audits go deep into server configuration, CDN behavior, and log file analysis to surface the issues standard crawlers miss.
Frequently Asked Questions: Vary Header SEO
Does the Vary header directly affect Google rankings?
Not directly, but its effects do. Vary misconfiguration can cause Google to index wrong content versions, experience poor performance (which affects Core Web Vitals), or waste crawl budget on repeated requests. These indirect effects absolutely impact rankings. A site where Googlebot is being served cached mobile content on desktop URLs, for example, will see real ranking degradation.
Should I include Vary: Accept-Encoding on all my pages?
Your web server should handle this automatically if compression is enabled. Nginx adds Vary: Accept-Encoding when the gzip module is active. Apache’s mod_deflate does the same. Verify it’s present by checking response headers on a few pages, but you shouldn’t need to manually configure it per-page in most setups.
What does Vary: Cookie do to my site’s cacheability?
It effectively makes pages uncacheable at the CDN level, since every unique cookie value creates a separate cache entry and most users have unique cookie values. If your CMS or framework is emitting Vary: Cookie on public pages (common with WordPress and certain caching plugins), this is a caching bug. Public pages should strip cookies before the CDN cache layer or at minimum not include Cookie in the Vary header for cached content.
How does Vary header interact with AMP pages?
AMP pages served through the Google AMP Cache don’t go through your CDN’s Vary handling—they’re cached and served by Google’s infrastructure directly. For non-AMP pages where you serve AMP variants, use separate URLs and canonical/amphtml links rather than content negotiation with Vary headers.
Can Vary headers cause duplicate content issues?
Yes, in the case of dynamic serving. If your site serves substantially different HTML for the same URL based on User-Agent, and Google somehow indexes both versions (via different crawl configurations), you could see duplicate content flags. This is another reason Google recommends responsive design over dynamic serving—it eliminates this class of problem entirely.
