> ## Documentation Index
> Fetch the complete documentation index at: https://bunnynet-cb9733c2-support-migration.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Smart Cache

> Prevent accidental caching of sensitive content by limiting caching to known static file types.

By default, Bunny caches all responses from your origin that include cacheable headers like `Cache-Control` or `Expires`. If your server is misconfigured, this could result in sensitive or personalized content being cached and served to other users.

Smart Cache prevents this by only caching responses with specific file extensions and MIME types. Dynamic content passes through to your origin on every request.

<Note>
  Pull Zones accelerated by Bunny DNS have Smart Cache enabled by default.
</Note>

## Enable Smart Cache

<Steps>
  <Step title="Open your Pull Zone settings">
    Go to **CDN** > **Pull Zones** and select your zone.
  </Step>

  <Step title="Navigate to Caching settings">
    Click **Caching** in the left menu.
  </Step>

  <Step title="Enable Smart Cache">
    Check the **Smart Cache** option at the top of the page.
  </Step>
</Steps>

When Smart Cache determines a request is cacheable, the standard cache expiration time settings apply.

## Cacheable extensions

Smart Cache only caches files with these extensions:

| Images          | Video          | Audio          |
| --------------- | -------------- | -------------- |
| avif, bmp, gif  | 3g2, 3gp, asf  | aif, flac, mid |
| heic, ico, jpg  | avi, flv, m3u8 | midi, mp3, mpa |
| jpeg, pict, png | m4u, mkv, mp4  | ogg, wav, wma  |
| svg, svg2, tif  | mpg, swf, ts   |                |
| tiff, webp      | vob, webm, yuv |                |

| Fonts         | Documents           | Archives          |
| ------------- | ------------------- | ----------------- |
| eot, otf, ttf | csv, doc, docx      | 7z, bz2, gz       |
| woff, woff2   | odt, pdf, ppt       | iso, jar, rar     |
|               | pptx, ps, psd       | tar, xz, zip, zst |
|               | srt, txt, xls, xlsx |                   |

| Code & Binaries   | Other         |
| ----------------- | ------------- |
| bat, class, css   | apk, bin, dat |
| dll, ejs, exe, js | dmg, eps, pls |

## MIME types excluded from caching

These MIME types are never cached, regardless of extension:

| MIME Type          |
| ------------------ |
| `text/html`        |
| `application/json` |
| `application/xml`  |

## Override Smart Cache

To cache a file type that Smart Cache normally excludes, create an Edge Rule with the **Override Cache Time** action. This bypasses Smart Cache's decision and caches the response for your specified duration.

<Steps>
  <Step title="Create an Edge Rule">
    Go to **Edge Rules** in your Pull Zone settings and click **Add Rule**.
  </Step>

  <Step title="Set the action">
    Select **Override Cache Time** and enter the cache duration in seconds.
  </Step>

  <Step title="Add conditions">
    Add conditions to match the requests you want to cache, such as file
    extension or URL path.
  </Step>
</Steps>

<Info>
  This is useful for caching HTML pages or API responses that you know are safe
  to cache, such as static site generators or public API endpoints.
</Info>

## Improving your cache hit rate

A healthy Pull Zone typically sees a cache hit rate above 95%. A rate below 70% usually points to a configuration issue causing requests to be fetched from your origin instead of served from cache. Common causes and fixes:

* **Missing or restrictive `Cache-Control` headers:** Bunny follows the origin's `Cache-Control` header to decide whether and how long to cache. Check it with `curl -I https://your-zone.b-cdn.net/path/file.css`. If it's missing, set to `no-cache`, or has a very low `max-age`, the file won't cache well. Set an appropriate `max-age`, or override caching with an Edge Rule (see [Override Smart Cache](#override-smart-cache)).
* **Changing query strings:** Each unique URL, including its query string, is cached separately, so `/style.css?v=1` and `/style.css?v=2` are two cache entries. If the query string changes but the content doesn't, disable **URL Query String** under [Vary Cache](/cdn/vary-cache#url-query-string) so all variants share one cache file. Review your workflow first, since this affects every query-string variant.
* **New or recently purged zone:** Cache hit rate builds up over time. A brand-new or just-purged zone shows a low rate until traffic warms the cache, usually within a day.
* **Dynamic content via Smart Cache:** With Smart Cache enabled, dynamic content is treated as non-cacheable, which lowers the reported rate on zones that serve many dynamic assets.
* **Infrequently requested files:** Files that aren't requested for a period (typically 5 to 7 days) may be evicted from cache. The more popular a file, the higher its hit rate.
* **Mostly static content:** Consider [Perma-Cache](/cdn/perma-cache) to permanently store files on edge storage. Note that Perma-Cache hits are still reported as MISS in CDN cache metrics.
* **Simultaneous mass requests:** For livestreaming or live events where many users request the same uncached asset at once, enable [Request Coalescing](/cdn/request-coalescing) to funnel them into a single origin request.

## Video and large file delivery

Bunny CDN supports HTTP range requests, which let players fetch specific byte ranges so viewers can skip ahead in a video. Range requests are enabled by default for cached content. For content that isn't cached yet, or videos that buffer when you skip ahead or large files that are only seekable once fully downloaded, two settings help:

* **Enable Optimize for Video Delivery:** In your Pull Zone **Caching** settings, enable **Optimize for Video Delivery**. This slices large files into small chunks that are fetched independently, so any part of a file, including range requests against uncached content, can be served at any time regardless of cache state. Without it, an uncached file is downloaded from the origin as one large object and is only seekable from the start until fully cached.
* **Encode video with the header at the start:** If seeking still fails even when the file is cached, your video likely has its metadata (the moov atom) at the end of the file, forcing the browser to download the whole file before it can play. Re-encode with a web-optimized (fast-start) preset so the header sits at the beginning.

<Note>
  RTMP streaming isn't supported on the CDN. For live and on-demand video streaming, use [Bunny Stream](/stream).
</Note>

## ETag support

Bunny CDN supports the [`ETag`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) response header, which identifies a specific version of a file so browsers and the CDN can tell whether a cached copy is still valid.

* If your origin sends an `ETag` and **Optimize for Video Delivery** is disabled, Bunny passes the `ETag` through and caches the response accordingly.
* If Bunny compresses the file (Brotli or Gzip), the `ETag` is converted to a weak `ETag` prefixed with `W/` (for example, `"123456789"` becomes `W/"123456789"`), since compression changes the file's binary output.
