A Manila travel site added Vary: User-Agent to serve mobile pages, following a tutorial. Their cache-hit ratio collapsed to 11% overnight.
The myth: vary on User-Agent to handle devices. The reality: there are thousands of unique User-Agent strings. Every browser version, every device, became a separate cache entry. They had effectively disabled caching.
What we changed: we removed the Vary header, switched to a responsive design served from one cached HTML document, and used CSS media queries instead of server-side device sniffing.
Result: cache-hit ratio recovered to 92%, Manila TTFB dropped from 480ms to 35ms, and origin load fell by an order of magnitude.
Vary on User-Agent shatters your cache into infinite fragments. Respond responsively, cache once.
The number that mattered: 92% cache-hit, back from 11%.
Edge of Glory
@EdgeOfGloryCDN
The myth of Vary: User-Agent for mobile
This post was published in the Telegram channel Edge of Glory (@EdgeOfGloryCDN). All its posts are on the channel page.
Open on Telegram