bunny.net × Astro

routeRules

Caching

One rule in the config turns into the headers the bunny.net CDN reads.

Generated at2026-09-21T07:12:26.129Z

On the live site this timestamp holds still for a minute, because the edge answers from its cache. Every other page changes on every reload.

The rule

// astro.config.mjs
routeRules: {
  "/cached": { maxAge: 60, swr: 600, tags: ["demo"] },
}

The headers it produces

Cache-Control: public, max-age=0, must-revalidate, s-maxage=60, stale-while-revalidate=600
CDN-Tag: demo,astro-path:/cached

s-maxage is for the CDN and max-age is for the browser. Splitting them is what makes a purge take effect at once.

Turn Smart Cache off first

Smart Cache only caches known static file extensions, and HTML is not one of them. It is on by default, and while it is on this rule does nothing:

bunny api POST /pullzone/<pull-zone-id> --body '{"EnableSmartCache": false}'

The adapter then sets Cache-Control: private, no-store on every other page, so nothing personal is cached by accident.

Purging

await Astro.cache.invalidate({ tags: ["demo"] });

That calls the bunny.net purge API for the demo tag. Give the script BUNNY_API_KEY and BUNNY_PULLZONE_ID first.