Netlify
Last reviewed: 2026-10-27 · Applies to: Netlify CDN, Functions, Edge Functions, durable cache, Cache API, @netlify/cache, @netlify/plugin-nextjs 5.x
Contents
- When to read this
- How to detect
- Default recipe
- Rules and gotchas
- Headers and variants
- Tags and purge
- Durable cache and Cache API
- Framework integration
- Status headers
- Version notes
- Verify
- Sources
When to read this
When the app deploys to Netlify. Netlify's caching specifics in this file came from Netlify's own agent guidance rather than a public docs page; confirm details against docs.netlify.com before relying on exact limits.
How to detect
netlify.toml, _headers/_redirects files, netlify/functions/ or netlify/edge-functions/, @netlify/* deps, response headers x-nf-request-id, cache-status: "Netlify Edge"; …, server: Netlify.
Default recipe
# Function response cached at the edge, shared across nodes via the durable cache
Cache-Control: public, max-age=0, must-revalidate
Netlify-CDN-Cache-Control: public, durable, s-maxage=3600, stale-while-revalidate=86400
Netlify-Cache-Tag: product:123,all
Netlify-Vary: query=page|sortnetlify.toml example: assets/snippets/cdn/netlify.toml.
Rules and gotchas
- Dynamic responses (Functions, Edge Functions, proxies) aren't cached unless headers opt in. Only GET is cached.
- Header precedence:
Netlify-CDN-Cache-Control(Netlify only) >CDN-Cache-Control>Cache-Control(the latter two pass downstream). - Basic auth on any page disables caching for the entire site.
- Static assets are fresh up to a year at the edge and a shorter
max-ageis ignored; they change only on deploy or purge. Atomic deploys invalidate automatically. - Without
Netlify-Vary: query=…, the full query string is the key andutm_*/fbclidfragment the cache. - A URL must return the same
Netlify-Varyon every response; the first cached response's instructions win. - Each request may hit a different cache instance: without
durableor steady traffic, expect several misses before hits. - Never opt sensitive content out of deploy invalidation (
Netlify-Cache-ID); it could stay publicly cached after a fix. netlify devdoesn't emulate the CDN cache; test on a deploy preview.- Purge rate limit: each tag (or the site) can be purged twice per 5 seconds; beyond that you get 429s. Debounce webhook purges.
- Browsers get
Cache-Control: public, max-age=0, must-revalidatefor static files by default, which is right forindex.htmland other fixed URLs. Fingerprinted build assets need an explicitCache-Control: public, max-age=31536000, immutablerule for their path innetlify.toml[[headers]]or_headers. Netlify's own build-asset handling may already add it for some frameworks; check withcurl -I.
Headers and variants
Defaults: static Netlify-CDN-Cache-Control: public, s-maxage=31536000, must-revalidate; dynamic Cache-Control: public, max-age=0, must-revalidate.
Netlify-Vary keys on specific parts instead of whole headers:
Netlify-Vary: query=item_id|page, country=es+de|us, cookie=ab_test|is_logged_in, language=en|es+pt, header=Device-TypeYou can't vary on Accept*, Cache-Control, Connection, Content-Length, Cookie, Host, If-*, Range, Referer, Upgrade, User-Agent headers directly; use the cookie=/language=/country= forms.
Tags and purge
Netlify-Cache-Tag: tag1,tag2(wins overCache-Tag, which passes downstream; set both when another CDN in front stripsCache-Tag). Case-insensitive, ≤ 1,024 chars per tag, ≤ 500 tags per response.- Purge from code:
purgeCache({ tags })from@netlify/functions(no args = whole site; optionstags,deployAlias,domain). - Purge API:
POST https://api.netlify.com/api/v1/purgewithsite_id/site_slugandcache_tags. Omittingcache_tagspurges the whole site; an empty list purges nothing. - No soft purge: purge is a hard purge. Use
stale-while-revalidateto soften expiry.
Durable cache and Cache API
durable(inNetlify-CDN-Cache-Control, serverless functions only, not Edge Functions): stores responses in a shared durable cache so other edge nodes reuse them instead of invoking the function. Eventually consistent, co-located with the functions region. Next.js runtime ≥ 5.5.0 uses it automatically.- Cache API (
caches.open/match/put) inside handlers: ≤ 100 lookups and ≤ 20 insertions/deletions per invocation; per region, not replicated; invalidated on redeploy; can't cache 206,Vary: *or non-GET; requirespublic, 2xx andmax-age/s-maxage≥ 1 s. Deletes are eventually consistent. No request collapsing. @netlify/cache:fetchWithCache(url, opts, { ttl, swr, tags, vary, durable }),cacheHeaders(),getCacheStatus(),needsRevalidation().
Framework integration
- Next.js:
@netlify/plugin-nextjs(v5) supports the Full Route Cache and Data Cache; static page responses are cached at the edge and revalidate by path or tag. - Nuxt
isrroute rules map to Netlify's CDN; Astro's experimentalcacheNetlify()setsNetlify-CDN-Cache-ControlandNetlify-Cache-Tagwith the durable cache.
Status headers
RFC 9211 Cache-Status, e.g. "Netlify Edge"; hit, "Netlify Edge"; hit; fwd=stale (SWR), "Netlify Durable"; fwd=uri-miss; stored=true; ttl=3600.
Version notes
- On-demand Builders are legacy; use
durable+ cache headers or framework ISR. - Next.js runtime 5.5.0+ uses the durable cache automatically.
- On-demand Builders (
builder()wrapper) for ISR-like behavior. - Relying on
Cache-Controlalone for function caching (no shared durable cache).
Verify
curl -s -o /dev/null -D - https://site.netlify.app/api/products | grep -iE 'cache-status|age|cache-control'
curl -X POST https://api.netlify.com/api/v1/purge -H "Authorization: Bearer $NETLIFY_TOKEN" \
-H 'Content-Type: application/json' -d '{"site_id":"'"$SITE_ID"'","cache_tags":["product:123"]}'