This week in caching: Vary header vs separate URLs for variants
Serving mobile/desktop or multi-language from one cache — two roads:
— Vary header (e.g. Vary: Accept-Encoding) keeps one URL and lets the cache store per-variant. Clean for encoding/compression. But Vary: User-Agent is a hit-rate killer — thousands of UA strings = thousands of cache entries for one page.
— Separate URLs (/en/, /de/, m.site.com): each variant is its own cacheable object with high hit rate, and it's SEO-friendly. Cost: routing/redirect logic and canonical tags.
— The middle path: normalize the varying input to a small set (UA → 'mobile'/'desktop' bucket) before it hits the cache key, so you get Vary's single-URL simplicity without the explosion.
Rule: Vary only on low-cardinality headers; for anything high-cardinality, bucket it or split the URL.
Bookmark: Smashing Magazine's 'Vary header' deep-dive on cache-key cardinality.
Cache Catch
@CacheCatch
This week in caching: Vary header vs separate URLs for variants
Этот пост опубликован в Telegram-канале Cache Catch. Подписаться можно по ссылке: @CacheCatch.