shiichan

Multiple versions per URL: Cache Rules now understands the Vary header

Hey there, it's Shiichan! Today I've got a nice little update that makes caching a bit smarter.

Cloudflare Changelog developers.cloudflare.com

What was announced?

Over on Cloudflare's Changelog, they announced that Cache Rules can now honor the Vary response header directly.

Your origin might serve different responses for the same URL, like different languages via Accept-Language or different formats via Accept. Now Cloudflare's cache reads that difference and returns the right version for each request.

The story so far

Until now, content that changed under the same URL was risky to cache, because you could end up serving the wrong version. To stay correct, you had to bypass the cache entirely, which meant leaving all that caching goodness on the table.

What changes

When your origin lists the request headers it varies on in the Vary header, those headers become part of the cache key, so a single URL can hold multiple cached versions.

The best part: you don't need to change any code on your origin or in your Worker. Content that used to bypass the cache can now be cached, which lifts your cache hit ratio too.

Dive Deep

For each header your origin varies on, you pick one of three actions.

  • normalize: collapses semantically equivalent header values to the same cache key, great for Accept / Accept-Language / Accept-Encoding and trims redundant versions.
  • passthrough: selects the version by the raw header value and forwards it to the origin unchanged, for when byte-for-byte differences should create versions.
  • bypass: bypasses cache whenever that header name appears in Vary, for per-user values or headers with too many possible values to cache safely.

This all follows the standard HTTP caching behavior from RFC 9111 / RFC 9110. It's available on every plan: Free, Pro, Business, and Enterprise.

You can configure it from the Cloudflare dashboard or the Rulesets API, and the details live in the Cache Rules Vary setting docs.

If you want finer control from Workers, pair it with the cf.vary property.

Wrap-up

  • The same URL can now cache different responses per language or format, based on the Vary header
  • Choose normalize / passthrough / bypass per header
  • No origin or Worker code changes needed, and previously-bypassed content can now be cached for higher hit ratios
  • Available on all plans, configurable via the dashboard or the Rulesets API

A welcome update for anyone running multilingual sites or content negotiation, or just chasing a higher cache hit ratio!