> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sevalla.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> These are the docs for Sevalla, a platform for deploying applications, databases, static sites, object storage and load balancers. The dashboard is at https://app.sevalla.com.
> Bold text in steps is an exact dashboard label.
> To act on a Sevalla account, prefer the Sevalla MCP server (https://mcp.sevalla.com/mcp, see https://docs.sevalla.com/ai-agents/overview.md), then the Sevalla CLI (https://docs.sevalla.com/developer-tools/cli.md), then the REST API (https://api-docs.sevalla.com, OpenAPI spec at https://api.sevalla.com/v3/openapi.json).
> Every page index is at https://docs.sevalla.com/llms.txt.

# CDN and edge caching

> Cache an application's static files and pages on Cloudflare's network: turn on the CDN or edge caching, see what gets cached and for how long, control it with headers, and purge the cache.

Sevalla can cache an application's responses on Cloudflare's network, so visitors get them from a location near them instead of from your application. The **CDN** caches static files such as images, scripts and stylesheets. **Edge caching** also caches rendered pages and every other response that's safe to cache. Both are off by default, included at no extra cost, and work on every domain of the application, including its `sevalla.app` domain.

## How caching works

Every request to the application's domains passes through Cloudflare. With the CDN or edge caching on, Cloudflare answers a `GET` request from its cache when it has a copy, and otherwise forwards it to your application and stores the response if it can.

| | CDN only | Edge caching on |
| - | - | - |
| What can be cached | Requests for files with a [cached extension](#cached-file-extensions), such as `.css`, `.js`, `.png` or `.woff2` | Every `GET` request, including HTML pages and API responses |
| Good for | Any application | Sites whose pages are the same for every visitor: marketing sites, blogs, documentation |

<Warning>
  Edge caching doesn't look at request cookies. A page that changes per user (a dashboard, a cart, a signed-in view) is served from the cache to everyone unless its response sets a cookie or sends `Cache-Control: private` or `no-store`. Don't turn on edge caching for highly dynamic applications without checking those headers.
</Warning>

### What is never cached

Sevalla always forwards these requests to your application, with or without caching:

* Requests with a method other than `GET`, such as `POST`, `PUT` and `DELETE`.
* Requests with an `Authorization` header.
* Range requests (a `Range` header), for example for video seeking, and WebSocket upgrades.
* Responses with a status other than `200`, `301`, `302` or `303`.
* Responses that set a cookie (`Set-Cookie`). For files with a cached extension, Sevalla first removes Cloudflare's own `__cf_bm` bot-management cookie, so those files can still be cached.

### How long responses stay cached

If your response has a `Cache-Control` header, Sevalla leaves it as it is and Cloudflare follows it: `no-store` or `private` keeps the response out of the cache, and `s-maxage` or `max-age` sets how long it stays. If the response has no `Cache-Control` header, Sevalla adds one:

| Response status | Kept for |
| - | - |
| `200` | 30 days |
| `301` | 120 minutes |
| `302`, `303` | 20 minutes |

For HTML pages, the added header lets Cloudflare keep the page for that time but tells browsers to check again on every visit (`public, max-age=0, must-revalidate, s-maxage=<time>`). Other files get the same time for browsers and Cloudflare (`public, max-age=<time>, s-maxage=<time>`).

The cache key is the full URL, including the query string: `/app.js?v=2` and `/app.js?v=3` are cached separately.

### When the cache is cleared

Sevalla purges the cache of every domain of the application after every successful [deployment](/applications/deployments), so visitors get the new version. You can also [purge it yourself](#purge-the-cache) at any time.

Cached copies of your files and pages are stored on Cloudflare's network, outside the application's location, for as long as they stay in the cache.

## Turn on the CDN or edge caching

<Steps>
  <Step title="Open the caching settings">
    In the sidebar, click **Applications**, then click the application. Click the **Networking** tab, then click **Update settings** in **CDN & Edge caching**.
  </Step>

  <Step title="Switch them on">
    Turn on **CDN**, **Edge caching**, or both. Each switch applies as soon as you flip it, without a deployment.
  </Step>

  <Step title="Close the sheet">
    Click **Done**.
  </Step>
</Steps>

<Frame>
  <img className="block dark:hidden" src="https://assets.sevalla.com/screenshots/light/app-networking-cdn-update.png" alt="The Update caching sheet with a CDN switch and an Edge caching switch" width="576" />

  <img className="hidden dark:block" src="https://assets.sevalla.com/screenshots/dark/app-networking-cdn-update.png" alt="The Update caching sheet with a CDN switch and an Edge caching switch" width="576" />
</Frame>

The section then reads **CDN is enabled** and **Edge caching is enabled**. The application's **Overview** tab shows the same status in its Cloudflare card. Cloudflare locations can take up to a minute to apply a change.

To turn caching off, open the same sheet and turn the switches off. With both off, every request goes to your application. Copies cached before can be served again if you turn caching back on before they expire, so [purge the cache](#purge-the-cache) when you turn it back on after changing content.

## Purge the cache

Purging removes every cached response of every domain of the application, for the CDN and edge caching together. The next requests go to your application and fill the cache again.

On the application's **Networking** tab, click **Purge cache** in **CDN & Edge caching**. There's no confirmation: the dashboard shows **Cache purged.** when it's done.

## Control caching from your application

* **Keep a response out of the cache:** send `Cache-Control: no-store` or `Cache-Control: private`, or set a cookie in the response.
* **Cache a response for a set time:** send `Cache-Control: public, s-maxage=<seconds>`. `s-maxage` applies to Cloudflare; `max-age` applies to browsers, and to Cloudflare when there's no `s-maxage`.
* **Change a file without waiting for its cache to expire:** give it a new URL (`app.3f9c2.js` or `app.js?v=3`), or purge the cache.
* **Bypass the cache for API calls:** send them with an `Authorization` header, or use a method other than `GET`.

## Cached file extensions

With only the CDN on, Sevalla caches requests whose path ends in one of these extensions (matched without regard to case; the file's content type doesn't matter):

`7z`, `afm`, `apk`, `avi`, `avif`, `bmp`, `bz2`, `cff`, `css`, `cur`, `data`, `dmg`, `doc`, `docx`, `eot`, `epub`, `exe`, `ffil`, `flac`, `flv`, `gif`, `gz`, `heic`, `heif`, `ico`, `img`, `iso`, `jfif`, `jpeg`, `jpg`, `js`, `json`, `lwfn`, `m4a`, `m4v`, `map`, `md`, `mid`, `midi`, `mkv`, `mov`, `mp3`, `mp4`, `mpga`, `odp`, `ods`, `odt`, `ogg`, `ogv`, `otf`, `pdf`, `pfb`, `pfm`, `png`, `ppt`, `pptx`, `pro`, `qt`, `rar`, `rtf`, `scss`, `std`, `svg`, `svgz`, `tar`, `tgz`, `tif`, `tiff`, `ttf`, `txt`, `wasm`, `wav`, `webm`, `webp`, `wmv`, `woff`, `woff2`, `xls`, `xlsx`, `xml`, `xsf`, `zip`, `zst`.

Edge caching doesn't use this list: it caches every path.

## API and CLI

| Task | API | CLI |
| - | - | - |
| Turn the CDN on or off | [Toggle CDN](https://api-docs.sevalla.com/v3/applications/toggle-cdn) | `sevalla apps cdn-toggle <app-id>` |
| Turn edge caching on or off | [Toggle edge cache](https://api-docs.sevalla.com/v3/applications/toggle-edge-cache) | Not available |
| Purge the cache | [Purge edge cache](https://api-docs.sevalla.com/v3/applications/purge-edge-cache) | `sevalla apps purge-cache <app-id>` |

The toggle operations switch the current state: calling one twice turns the feature back off.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.