Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
netlify avatar

Netlify Caching

  • 1.4k installs
  • 31 repo stars
  • Updated August 4, 2026
  • netlify/context-and-tools

netlify-caching is a Netlify skill that guides CDN cache header configuration, stale-while-revalidate, on-demand purge, and framework-specific caching patterns for developers who need fast, correctly invalidated Netlify

About

netlify-caching is a guide skill for controlling caching on Netlify's CDN when configuring cache headers, stale-while-revalidate, on-demand cache purge, or understanding default CDN behavior. Static assets are cached on the CDN for 1 year and invalidated on every deploy, while browsers always revalidate with `max-age=0, must-revalidate`; dynamic function and edge responses are not cached by default. The skill documents Cache-Control, Netlify-CDN-Cache-Control, cache tags, durable cache, and framework-specific patterns. Developers reach for it when deployed Netlify apps serve stale content, miss cache opportunities, or need precise purge behavior after releases.

  • Explains the three-tier header precedence: Netlify-CDN-Cache-Control, CDN-Cache-Control, and Cache-Control
  • Default behavior reference: static assets cached 1 year on CDN, dynamic responses never cached by default
  • Common patterns for stale-while-revalidate, on-demand cache purge, and framework-specific caching
  • Covers cache tags, durable cache, and edge-function behavior
  • Ready-to-use TypeScript response examples for production-grade caching

Netlify Caching by the numbers

  • 1,426 all-time installs (skills.sh)
  • +127 installs in the week ending Aug 5, 2026 (Skillselion tracking)
  • Ranked #157 of 1,435 DevOps & CI/CD skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/netlify/context-and-tools --skill netlify-caching

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.4k
repo stars31
Last updatedAugust 4, 2026
Repositorynetlify/context-and-tools

How do you configure Netlify CDN cache headers?

Correctly configure CDN caching headers and purge behavior on Netlify so their deployed apps stay fast and up-to-date.

Who is it for?

Developers shipping SSR, edge functions, or static sites on Netlify who need correct CDN caching and purge behavior after deploys.

Skip if: Developers on Vercel, AWS CloudFront-only stacks, or local-only development with no Netlify CDN in the path.

When should I use this skill?

The user configures Netlify cache headers, stale-while-revalidate, on-demand purge, cache tags, or asks why Netlify responses are stale or uncached.

What you get

Correct Cache-Control and Netlify-CDN-Cache-Control headers, cache tag setup, and an on-demand purge workflow for deployed apps.

  • Cache header configuration
  • Cache tag setup
  • On-demand purge workflow

By the numbers

  • Static CDN cache TTL: 1 year, invalidated on every deploy
  • Browser default: max-age=0, must-revalidate

Files

SKILL.mdMarkdownGitHub ↗

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:

HeaderWho sees itUse case
Netlify-CDN-Cache-ControlNetlify CDN only (stripped before browser)CDN-only caching
CDN-Cache-ControlAll CDN caches (stripped before browser)Multi-CDN setups
Cache-ControlBrowser and all cachesGeneral 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",
  },
});

Immutable Assets

For fingerprinted files (hash in filename):

# netlify.toml
[[headers]]
for = "/assets/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"

Cache Tags and On-Demand Purge

Tag responses for selective cache invalidation:

return new Response(body, {
  headers: {
    "Netlify-Cache-ID": "product,listing",
    "Netlify-CDN-Cache-Control": "public, s-maxage=86400",
  },
});

Purge by tag:

import { purgeCache } from "@netlify/functions";

export default async () => {
  await purgeCache({ tags: ["product"] });
  return new Response("Purged", { status: 202 });
};

Purge entire site:

await purgeCache();

Responses with Netlify-Cache-ID are excluded from automatic deploy-based invalidation — they must be purged explicitly.

Cache Key Variation

Customize what creates separate cache entries:

return new Response(body, {
  headers: {
    "Netlify-Vary": "cookie=ab_test|is_logged_in",
    // Other options: query=param1|param2, header=X-Custom, country=us|de, language=en|fr
  },
});

Framework-Specific Caching

Next.js

ISR uses Netlify's durable cache automatically (runtime 5.5.0+). revalidatePath and revalidateTag trigger cache purge.

Astro / Remix

Full control over cache headers in server routes. Set Netlify-CDN-Cache-Control in responses for CDN caching.

Nuxt

Default Nitro preset handles caching. ISR-style patterns use routeRules with swr or isr options.

Vite SPA

Static assets are cached by default. API responses from Netlify Functions need explicit cache headers.

Debugging

Check the Cache-Status response header:

  • HIT — served from cache
  • MISS — generated fresh
  • REVALIDATED — stale content was revalidated

Constraints

  • Basic auth disables caching for the entire site
  • Durable cache is serverless functions only (not edge functions)
  • Same URL must return identical Netlify-Vary headers across responses
  • Deploy invalidation is scoped to deploy context (production vs preview)

Related skills

How it compares

Choose netlify-caching when tuning Netlify-specific CDN headers and purge behavior rather than generic HTTP caching advice that ignores Netlify-CDN-Cache-Control and deploy invalidation.

FAQ

How long are static assets cached on Netlify CDN?

netlify-caching documents that Netlify caches static assets on the CDN for 1 year and invalidates them on every deploy, while browsers revalidate with `max-age=0, must-revalidate` without extra configuration.

Are Netlify function responses cached by default?

netlify-caching states dynamic responses from functions, edge functions, and proxied routes are not cached by default; developers must add Cache-Control or Netlify-CDN-Cache-Control headers to enable CDN caching.

DevOps & CI/CDdeployinfra

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.