vercel/vercel-plugin/cdn-caching
Claude Code and agent skill by vercel/vercel-plugin
- vendor
Checking that the SKILL.md file is still in the repository.
Debug Vercel CDN caching — cache hit rate, stale content, revalidation behavior, ISR + PPR, per-request cache reasons (cacheReason) and PPR state (ppr_state), and costs.
Install
npx vskill@latest install vercel/vercel-plugin/cdn-cachingSKILL.md
The same SKILL.md was published earlier as vercel/vercel-plugin/cdn-caching.
Vercel Caching
You are an expert in understanding Vercel's caching infrastructure, and how the CDN Cache, ISR, and PPR work.
Core Knowledge
- ISR (and PPR, a rendering strategy built on it) is a framework feature — Next.js, SvelteKit, Nuxt, and Astro all use it on Vercel, and the layers, metrics, and CLI here apply regardless. (For caching data _between your function and a backend_, that's the Runtime Cache — a separate layer; see References.)
- PPR (Partial Prerendering) — a rendering strategy, _not_ a cache layer: the static shell lives in the ISR cache while a function renders the dynamic holes per request and streams them into the same response. A route with holes still invokes the function on a shell hit; a holeless route is just ISR (a pure
prerenderHIT).
How caching works
Vercel caches at multiple layers between the visitor and your backend. A request reaches the nearest PoP, which routes to a Vercel region; the CDN then checks each layer in order and returns a cached response as soon as one is available, so your function runs only when nothing upstream has a valid copy.
Cache layers
- CDN cache — regional, ephemeral. On a hit the region returns the response with no function call. Reads/writes are free.
- ISR cache — durable, in a single Function region. On a CDN miss, Vercel reads here _before_ invoking your function (cache shielding), then replicates the result back to the CDN. Scoped to its deployment (a new deploy doesn't reuse it); kept until revalidated or unaccessed for 31 days; reads/writes are billed in 8 KB units.
- Function invocation — runs only if neither cache has a valid copy. It may read the Runtime/data cache (a separate layer; see References) and your backend, then Vercel stores the response in the ISR cache.
- Image cache — optimized images, cached on the CDN after the first transform.
- Purges propagate globally in ~300 ms.
Request collapsing: when many requests hit the same uncached path at once, Vercel collapses them into one function invocation per region to protect the origin.
Key concepts
- Cache hit rate — share served from cache (
HIT/STALE/PRERENDER) versus origin (MISS/REVALIDATED). Measure it over _cacheable_ requests — excludeBYPASSand(not set)(redirects, errors, uncacheable methods), or they drag the ratio down for non-cache reasons. Low hit rate means more origin load and higher latency. - Revalidation — refreshing cached content. Time-based runs automatically after an interval; on-demand runs when you call an API. Both use stale-while-revalidate: visitors keep getting the cached version while the new one regenerates in the background.
- Invalidate vs. dangerously-delete — two ways to clear content, with very different blast on hit rate:
- _Invalidate_ (
invalidateByTag, Next.js 16+revalidateTag(tag, 'max')) = stale-while-revalidate. Keeps serving stale while refreshing in the background → response showsx-vercel-cache: STALE. - _Dangerously-delete_ (
dangerouslyDeleteByTag, Next.jsupdateTag,revalidatePath, orrevalidateTag(tag)with no profile) = hard removal. The next request blocks in the foreground to regenerate →x-vercel-cache: REVALIDATED. - Cache tags & blast radius — tags group cached entries so one call can clear many. A coarse tag attached to thousands of paths has a large _blast radius_: a single write drops them all and the hit rate collapses until they re-warm. Prefer granular tags (
product-${id}) plus a roll-up tag. - Cache status (
x-vercel-cacheresponse header) — the _outcome_:
| Value | Meaning | |
|---|---|---|
HIT | Served from cache; no function ran | |
MISS | Not cached; origin/function ran | |
STALE | Served stale while revalidating in background (SWR / invalidate) | |
PRERENDER | Served a prerendered ISR/PPR shell | |
REVALIDATED | Foreground revalidation after a delete (or Pragma: no-cache) | |
BYPASS | Caching skipped (no-store, private, cookies, etc.) |
- Cache reason (
cacheReason) — the finer _explanation_ of that outcome for a single request. ThecacheResultmetric lumps allMISSes (and allSTALEs) together; the reason is the only thing that tells them apart. Eleven values: four for MISS, three map to BYPASS, three for STALE, one for REVALIDATED:
cacheReason | Refines | Meaning | |
|---|---|---|---|
cold | MISS | Cache empty for this key/variant (first request or evicted); the function ran | |
collapsed | MISS | Concurrent requests to one uncached path collapsed into a single invocation | |
error | MISS | An error prevented serving from cache | |
vary_key_denied | MISS | Origin's Vary header names a high-cardinality header (e.g. Cookie); response can't be cached | |
draft_mode | → BYPASS | Next.js Draft Mode active — bypassed so editors see live content | |
prerender_bypass | → BYPASS | Request matched the route's experimentalBypassFor config (e.g. bot UA on PPR) | |
crawler | → BYPASS | SEO-crawler UA — full response served so bots index real content | |
stale_time | STALE | Time-based revalidate interval elapsed; regenerating in background (SWR) | |
stale_tag | STALE | Tag invalidated (invalidateByTag / revalidateTag(tag, 'max')); regenerating | |
stale_error | STALE | A revalidation attempt failed; serving the last-good copy (a bug signal) | |
| Tag-based deletion | REVALIDATED | Tag deleted (dangerouslyDeleteByTag / revalidateTag(tag) with no profile / dashboard purge by tag); foreground regen |
A raw MISS with reason draft_mode / prerender_bypass / crawler is displayed as `BYPASS` (all usually expected). The three stale_* reasons separate a healthy time refresh (stale_time) from a broad-tag blast (stale_tag) from a failing regen (stale_error). Read cacheReason from the dashboard Logs "Reason" row, find matching requests with vercel logs requests --query 'cacheReason:stale_error' (needs Observability Plus or a Priority project), or aggregate with vercel metrics vercel.request.count --group-by cacheReason — the x-vercel-cache-reason header is internal-only and not visible via curl.
- PPR state (
ppr_state) — for a Partial Prerendering route, _how much_ of the response was prerendered versus computed per request. Only set onpartial_prerenderserves; blank for plainprerender/func/staticroutes and for cases the proxy can't classify (cold shell miss,BYPASS). Three states:
ppr_state | Meaning | |
|---|---|---|
| Static | Fully prerendered — no postponed state, so the function is not invoked for the body | |
| Partial | A static shell serves from cache + a postponed hole the function resumes per request | |
| Dynamic | The whole body is postponed and rendered by the function per request |
A Partial serve that still invokes the function is _not_ a cache miss — the cached shell serves immediately while the function fills only the dynamic holes. Read ppr_state from the dashboard Logs panel, filter on pprState with vercel logs requests --query (needs Observability Plus or a Priority project), or aggregate with vercel metrics vercel.request.count --group-by pprState. Like cacheReason, the x-vercel-ppr-state header is internal-only and not visible via curl.
Investigating cache issues
Reach for the Vercel CLI. vercel metrics gives aggregate numbers (requires Observability Plus); vercel logs requests shows per-request CDN behavior (status, cache result, path), and vercel logs shows the runtime logs a request produced.
Metrics need to be queried by team and project (-S <team> -p <project>). Filter production with --environment production (equivalent to --query 'environment:production'; the CLI's filter syntax is KQL — the older OData eq/and syntax is deprecated). --query/-q needs Vercel CLI 65.4+ (older CLIs use --filter/-f), and --environment needs 64.7+ (older CLIs use --prod). Run vercel metrics schema <metric> to discover dimensions; use --json for machine-readable output (CLI 58.1+; older CLIs use --format json). Since CLI 59.12, vercel metrics queries the Observability metrics API by default, which names dimensions in camelCase (cacheResult, requestPath, cacheTags) and counts requests with the count aggregation (the default for vercel.request.count; --aggregation sum is rejected there). Before 59.12 the CLI queries the legacy API, which uses snake_case names (cache_result, request_path) and OData filters; FF_LEGACY_METRICS=1 switches back to it only on CLI 59.12–65.11 (65.12 removed the flag). Remember `--limit` is per time bucket — with no --granularity, the CLI still picks a bucket size for the range.
Cache hit rate
Start here for an overall picture of how well caching is working.
Step 1 — overall split. Group vercel.request.count by cacheResult. Treat HIT, STALE, and PRERENDER as cache-served; focus investigation on MISS. Exclude BYPASS and (not set) when computing a hit rate over _cacheable_ traffic (see Debugging BYPASS traffic). STALE means stale-while-revalidate is working — dig into revalidation frequency in Analyzing ISR costs, not here.
Step 2 — where misses concentrate. Split the MISS bucket (and optionally STALE) by pathType, then by route or requestPath:
What to expect: prerender routes (static shells, ISR pages) should show a high share of HIT/PRERENDER. A prerender path with a disproportionate MISS count is your short list for per-path header inspection (curl above) and code review.
streaming_func routes render dynamically by default, but you can still cache them with Cache-Control headers — matching requests are cached on the CDN. Each cache entry varies by Vary headers (cookies, RSC, etc.) as well as path and query parameters, so expect more cache keys and a lower hit rate than a fully static prerender route.
Analyzing ISR costs
Once you know hit rate, quantify ISR spend and whether revalidation — not traffic volume — is driving it.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 15 Nov 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cdn-caching/SKILL.md
Popularity
- Repository stars
- 289
- Repository forks
- 60
- 7-day trend score
- 28
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/vercel/vercel-plugin/cdn-caching)