Technical & DevelopmentIntermediate
netlify-caching
Configure CDN caching and cache purging
Developer Setup
Setup & Installation
bash
npx skills add https://github.com/netlify/context-and-tools --skill netlify-cachingnpx skills add https://github.com/netlify/context-and-tools --skill netlify-cachingOr paste this URL into your assistant to install:
Overview
What This Skill Does
Controls how Netlify's CDN caches responses from functions, edge functions, and static assets. Covers Cache-Control header configuration, stale-while-revalidate patterns, durable cache for serverless functions, cache tag assignment, and on-demand purge via the Netlify Functions API.
Application
When to use this Skill
- Configuring integration settings for custom agent workflows.
- Optimizing query execution and response latency in production.
- Developing clean, standard-compliant implementations for enterprise services.
- Troubleshooting connection timeouts and authentication handshakes.
- Monitoring API rate limits and execution pipelines programmatically.
Documentation
Show Skills.md file
Caching on Netlify
Default Behavior
Static assets are cached automatically:
- CDN: cached for 1 year, invalidated on every deploy
- Browser: always revalidates (
max-age=0, must-revalidate) - No configuration needed
Dynamic responses (functions, edge functions, proxied) are not cached by default. Add cache headers explicitly.
Cache-Control Headers
Three headers control caching, from most to least specific:
| Header | Who sees it | Use case |
|---|---|---|
Netlify-CDN-Cache-Control |
Netlify CDN only (stripped before browser) | CDN-only caching |
CDN-Cache-Control |
All CDN caches (stripped before browser) | Multi-CDN setups |
Cache-Control |
Browser and all caches | General caching |
Common Patterns
// Cache at CDN for 1 hour, browser always revalidates
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, s-maxage=3600, must-revalidate",
"Cache-Control": "public, max-age=0, must-revalidate",
},
});
// Stale-while-revalidate (serve stale for 2 min while refreshing)
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, max-age=60, stale-while-revalidate=120",
},
});
// Durable cache (shared across edge nodes, serverless functions only)
return new Response(body, {
headers: {
"Netlify-CDN-Cache-Control": "public, durable, max-age=60, stale-while-revalidate=120",
},
});
Lines 1 - 46 of 131
Recommendations