How does Vary Cache work?

By default, each URL is cached based on the path only. BunnyCDN does not respect the Vary header returned from your origin, however, we have a built-in system to make this easy to set up with a few clicks in the dashboard.

The Vary Cache configuration, allows you to specify additional parameters for the caching key. Unless you specifically require a certain feature, these should be kept disabled to maximize performance and cache hit rate.

URL Query String

If enabled, the URL query string is used as part of the cache key. For example /image.jpg?v=1 and image.jpg?v=2 are treated as different files in the cache.

Browser WebP Support

If enabled, the cache key will be based on the browser's ability to display WebP images. This key is only applied for URLs with the following extensions: jpg, jpeg, webp, png, gif. This allows you to serve WebP based images from the same URL if your origin server supports that.

User Country Code

If enabled, the user's country code is used as part of the cache key, so a user connecting from France and a user connecting from Germany will have a different caching key. This can be useful for serving translation files from the same URL for example.

The user's country code is forwarded to your origin with each request with the CDN-RequestCountryCode header.

Enabling this will disable purging cache based on a specific URL.

Request Hostname

If enabled, the hostname used with the request is used as a part of the cache key. For example, www.example.com/image.jpg and www.example2.com/image.jpg would be treated as different files in the cache even if linked to the same pull zone.

Enabling this will disable purging cache based on a specific URL.

Desktop/Mobile

If enabled, this setting will use the User-Agent that the user provides on their request to judge if a client is mobile/desktop, varying the cache based on this, so you can have a desktop version of a file and a mobile version (e.g serve a different size if wanted). We send a CDN-MobileDevice header with a value of true/false to the origin based on our assessment of the request. 

Browser AVIF Support

If enabled, the cache key will be based on the browser's ability to display AVIF images. 

Cookie Value

With this option, you can specify a cookie that we will use to vary the cache. Once you select the option, a box will appear where you can enter the cookie names that we will vary the cache based on the value of

Table of Contents

Was this article helpful?
7 out of 8 found this helpful