Docs · Deploy
The page cache
homeport’s edge can keep a page your app rendered and answer the next visitor without reaching your app. It keeps a page only when your app asks, with a CDN-Cache-Control header. An app that doesn’t send it works as it did before.
Ask for it
Send the header on a page that is the same for everyone who sees it:
CDN-Cache-Control: max-age=60, stale-while-revalidate=300, stale-if-error=86400The edge reads only this header and removes it from what it sends on. Cache-Control is left for the browser, so s-maxage there doesn’t put a page in the edge’s cache.
| Directive | What it does |
|---|---|
max-age | How long the page is fresh. |
stale-while-revalidate | How long after that a visitor still gets the old page while the edge fetches a new one. This never wakes a sleeping app. |
stale-if-error | How long the old page can stand in when your app answers with a 5xx or can’t be reached. Not for a 4xx. |
Pages that differ per visitor
The edge skips a request that has an Authorization header. It doesn’t skip one with a cookie, because almost every visitor carries one, often only for analytics, and the cache would rarely be used. Your app decides which pages are public.
If a page might differ per visitor, leave the header off. As a second guard, the edge won’t keep an answer that has any of these:
Set-CookieVary: Cookie,Vary: AuthorizationorVary: *private,no-storeorno-cacheinCDN-Cache-Control
What the edge keeps
GETandHEADanswers with status 200 or 404.- One copy for each host, path and query, and for each value of the headers your
Varynames. - Copies last until they expire, you purge them, or a new release goes live, which drops them all.
Previews are never cached.
See what happened
Every answer the edge decides has a Cache-Status header, with a part named homeport:
| Value | Meaning |
|---|---|
homeport; hit; ttl=42 | A kept page, fresh for 42 more seconds. |
homeport; hit; ttl=-5; detail=stale | An old page, served while a new one is fetched. |
homeport; fwd=uri-miss; stored | Your app answered, and the edge kept it. |
homeport; fwd=uri-miss; detail=set-cookie | Your app answered, and the edge didn’t keep it. detail says why. |
Purge a page
Every process of your app (web, processes, workers, cron jobs and the release command) has a CDN_PURGE_URL variable. It is a private address, reachable only from inside your app, so a purge needs no token:
await fetch(process.env.CDN_PURGE_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ tags: ['post-42'] }),
})The body takes tags, paths or all: true, with at most 100 tags and paths together. A path starts with / and has no query: it purges that path for every query and every value of your Vary headers. The answer is 202, 400 for a bad body, or 429 with Retry-After past 100 purges at once, then 10 a second. A 202 means the purge was accepted. The edges carry it out a moment later.
To tag a page, send Cache-Tag (separated by commas) or Surrogate-Key (separated by spaces) with it, at most 128 tags, each made of visible ASCII characters. The edge doesn’t keep an answer with more, and visitors never see those headers.
An app without a domain, or one served under a path prefix of another app’s domain, has no CDN_PURGE_URL, so check that it is set before you call it. Its kept pages last their max-age.
A purged page is gone from the edge’s cache, and the next visitor gets a new one from your app. A page your app was already sending when the purge landed still reaches its visitor, but isn’t kept.
On Next.js, revalidateTag and revalidatePath don’t call CDN_PURGE_URL for you, and they need a shared cache first. See Next.js caching.
Pages your framework lists for the edge
Some frameworks list their static pages and page shells for the edge to serve, as the edge contract describes. The same purge reaches those: by path, by all, or by the Cache-Tag and Surrogate-Key your app sends with the page. A page with more than 128 tags, or one a purge can’t name, is still served, but only a purge by path or all reaches it.
A purge doesn’t drop these pages. It marks them to be checked with your app:
- The next request for a purged page asks your app with
If-None-Match. A 304 keeps the page, a 200 replaces it, and a 404 removes it. Requests that arrive meanwhile wait for that one check. - A purge never wakes a sleeping app. The next visitor to a purged page wakes it once and gets the new page. Pages the purge didn’t name are served while your app sleeps, as before.
- If the check fails or times out, the visitor gets the stored page, never an error. While your app is awake, the page is checked again behind later requests. A sleeping app isn’t woken for it again until the next purge.