Edge caching
Let Cloudflare serve public share pages, embeds and preview images from its cache, so people far from your server get them in tens of milliseconds.
With edge caching on, Cloudflare keeps the public views of a paste in its data centers: the share
page, the embed and the link preview image. A visitor near any Cloudflare location gets them
without a round trip to your server. Sniptide clears a paste's cached copies when someone changes
it, and a cached copy expires after EDGE_CACHE_TTL seconds at the latest.
Edge caching is off by default. It needs Cloudflare in front of the app with its proxy (the orange cloud) on, and it works on every Cloudflare plan, including Free.
What gets cached
Sniptide marks a response as cacheable only when every anonymous visitor would get the same one:
- The request is a
GETorHEADfor a share page (/<slug>or/@handle/name), its/embedor its/previewimage, with no query string. - The visitor has no session, no unlock cookie for a password-protected paste and no language chosen in Sniptide, and their browser asks for English.
Private, password-protected, burn-after-read and encrypted pastes still get a cached page, but only the page every stranger sees: "not found", the password form, the reveal button or the ciphertext. Signing in, unlocking or revealing goes past the cache. Raw files, the Markdown view for agents, the API, the MCP server and every page of the app stay uncached.
Cloudflare can't put a visitor's language in the cache key below Enterprise, so the cache rule below skips visitors whose browser asks for another language. They still get their language, straight from your server.
Views
A visitor served from the cache never reaches your server, so a cacheable share page counts its
view from the browser instead, with the same rules as before: not for the owner, crawlers, link
previews or prefetches. A visitor with JavaScript turned off isn't counted while edge caching is
on. The view count shown on a cached page can lag by up to EDGE_CACHE_TTL seconds.
Turn it on
-
In Cloudflare, create an API token with the Zone → Cache Purge permission for the zone your share links use. Copy the zone ID from the zone's Overview page.
-
Set these on the app and restart it:
EDGE_CACHE_TTL=300 CLOUDFLARE_ZONE_ID=<zone id> CLOUDFLARE_API_TOKEN=<token> -
Add the cache rule and the cache response rule below.
Without the Cloudflare token Sniptide can't clear cached copies, so a change can take up to
EDGE_CACHE_TTL seconds to show. Keep the TTL short in that case.
Add the cache rule
The cache rule lets Cloudflare cache the requests Sniptide may mark. In the zone, open Caching → Cache Rules → Create rule, choose Edit expression and paste this, with your own hostnames:
(http.host eq "sniptide.com" or http.host eq "app.sniptide.com")
and http.request.method in {"GET" "HEAD"}
and http.request.uri.query eq ""
and not http.cookie contains "session_token"
and not http.cookie contains "sniptide_unlock_"
and not http.cookie contains "sniptide-locale"
and not any(http.request.headers.names[*] in {"rsc" "next-action" "next-router-prefetch" "next-router-state-tree" "next-router-segment-prefetch"})
and not any(http.request.headers["accept"][*] contains "text/markdown")
and (
not any(http.request.headers.names[*] eq "accept-language")
or any(starts_with(lower(http.request.headers["accept-language"][*]), "en"))
)Then set:
- Cache eligibility: Eligible for cache.
- Edge TTL: Use cache-control header if present, bypass cache if not.
- Browser TTL: Respect origin TTL.
The router headers matter: Next.js hides them from Sniptide's proxy, so only this rule can keep a page's data requests out of the cache.
Add the cache response rule
The cache response rule keeps everything Sniptide didn't mark out of the cache, such as error pages and the pages of another site on the same hostname. Open Caching → Cache Rules → Cache Response Rules → Create rule, choose Edit expression and paste:
not any(http.response.headers["x-sniptide-edge"][*] eq "1")
or not http.response.code in {200 404}Set Cache-Control to no-store and turn on Cloudflare only.
Check that it works
Open a public paste in a private window twice. The second response carries
cf-cache-status: HIT. Edit the paste, wait a few seconds and load it again: the response is a
MISS with the new content.
| What you see | Cause | Fix |
|---|---|---|
cf-cache-status: DYNAMIC on every load | The cache rule didn't match. | Check the hostnames in the rule and that the request has no query string, session cookie or non-English language. |
BYPASS | The cache response rule matched, or the app didn't mark the response. | Check that EDGE_CACHE_TTL is set on the app and that the response carries x-sniptide-edge: 1. |
| Edits take minutes to show | Purges fail. | Look for [edge-cache] purge failed in the app's logs and check the token's permission and the zone ID. |