CDN for Next.js

Cache versioned Next.js bundles under /_next/static. Set a separate policy for rendered routes and bypass responses that depend on cookies or user identity.

Example cache policy
Public, cacheable resource
/_next/static/chunks/app.9e3f.js
Bypass shared cache
/account

Separate build assets from rendered pages

Cache /_next/static aggressively. Cache ISR and anonymous SSR HTML at Cloud CDN with purge on deploy or revalidate. Bypass preview, draft mode and user-specific App Router responses.

Hashed assets at every PoP

Use a long cache lifetime for build assets with versioned URLs. Set the font policy to match how the files are versioned.

ISR and HTML at the edge

Anonymous pages can be cached in Cloud CDN so revalidate events rebuild once, not per region.

Images beside the app

Use Cloud CDN image optimization for public imagery instead of making the Next.js origin resize every variant.

Configuration

Cloud CDN overview
  1. Point Cloud CDN at the Next.js origin

    Pull the Node, container or hosting origin that serves the app over HTTPS.

  2. Cache static and HTML separately

    Long TTL for hashed /_next/static. Shorter TTL plus purge for HTML and RSC payloads that can be shared.

  3. Bypass preview and session routes

    Draft mode, preview tokens and authenticated App Router routes must not be cached.

  4. Purge on deploy or revalidate

    Invalidate HTML when ISR revalidates or a production deploy goes live.

Operational outcomes

  • Next.js static files are cached globally
  • Shareable HTML can live at the edge
  • Preview and draft mode stay dynamic
  • Deploys can purge without waiting on TTL

Frequently asked questions

Does this replace the Vercel edge?

Use Cloud CDN when you host Next.js yourself, want an independent CDN, or run a multi-CDN design in front of the app origin.

Can I cache Server Components output?

Cache only responses that are identical for every anonymous visitor. Personalised RSC payloads must bypass cache.

How should middleware and cookies be handled?

If middleware sets shopper or session cookies on HTML, bypass cache for those routes or vary only on cache keys you fully control.

Does this work with the Next.js Image component?

You can keep the Next optimizer as origin, or point public images at Cloud CDN transformation instead.