What is Vary Cache?

The Vary Cache settings help you configure how the internal caching key for each request is configured. bunny.net does not follow the standard HTTP Vary header. Instead, multiple configuration options are provided in the Pull Zone Cache settings allow you to configure the caching behavior.

By default, all Vary Cache settings are disabled. Each URL is treated as a unique cache key based on the path and file name of the request. To add additional capabilities, you can enable different Vary Cache settings and generate the caching key based on different parameters.

Vary Cache Types

The following Vary Cache settings are currently available:

📘 Bunny Optimizer Notice

If Bunny Optimizer processing engine is enabled, bunny.net will automatically enable WebP and URL Query String Vary Cache settings for image files.

URL Query String

By default, the query string is ignored when constructing the caching key. This means that the following requests for example, would be treated as the same file:


The URL Query String setting allows you to enable the query string to be part of the caching key. If turned on, bunny.net will treat each of the URLs above as a separate file. This is useful for dynamic responses that are generated based on query parameters or to assist with cache purging.

User Country Code

The User Country Code setting allows you to include the end-user's GeoIP country code as part of the caching key. This means your backend can deliver a different file based on the user's location which will then be cached separately based on where the user is coming from.

🚧 Cache HIT Rate Warning

Country Code based caching will include a different copy of each file based on the country of the user. This can create a large cache cardinality and significantly decrease the Cache HIT rate. Only use this if each country is supposed to receive their own content type.

🚧 Purging Warning

Enabling User Country Code vary setting will disable individual URL cache purging for the Pull Zone. You will only be able to clear cache using the full zone purging.

Browser WebP Support

The WebP support allows you to configure bunny.net to store two versions of image files depending on the web browser's WebP format support. If the browser supports the WebP format, a different caching key will be generated.

This way, you can serve optimized web images from the same URL transparent to your end-users based on if their browser supports the new format or not.

📘 Supported Image Extensions

The WebP Vary Cache only works with image files for specific extensions. Currently the following extensions are supported: jpg,jpeg,webp,png,gif

Requested Hostname

The Requested Hostname setting allows you to configure bunny.net to use the actual hostname that came as part of the request as the caching key. A request to the same Pull Zone for example with a custom hostname, such as cdn.mydomain.com and mydomain.b-cdn.net would then each keep their own version of the file.

This allows your origin to dynamically return content based on the domain that is being requested. It is recommended to combine this with the Forward Host Header setting.

How to configure Vary Cache?

To configure Vary Cache behavior, you can follow the following steps:

  1. Visit your Pull Zone details page
  2. Open the Cache panel in the left-side menu
  3. Open the General panel inside of the Cache panel
  4. Select the desired Vary Cache behaviors
  5. Click on the Save Vary Configuration button

Table of Contents

Was this article helpful?
14 out of 23 found this helpful