CDN for Sanity

Set cache policy for pages built from published Sanity content. Use publication events to refresh affected URLs and keep draft previews outside the public cache.

Example cache policy
Public, cacheable resource
/articles/published-guide
Bypass shared cache
/preview/draft

Refresh frontend content when documents change

Cache the Sanity-powered front end and images at Cloud CDN. Bypass Studio and preview. Purge when documents are published.

Published frontend pages

Cached public pages can be served without querying Sanity again until they expire or are invalidated.

Images adapted at the edge

Use one Sanity asset and create layout-specific variants at delivery time.

Studio stays off the CDN cache

Editors work on Sanity. Readers hit Cloud CDN.

Configuration

Cloud CDN overview
  1. Connect the front-end origin

    Pull the Next.js, Remix or static site that reads Sanity.

  2. Cache public routes

    Bypass preview and draft mode. Cache published HTML and assets.

  3. Purge from webhooks

    Map published document types to URLs and purge them.

  4. Attach the site domain

    Enable TLS and cut over DNS.

Operational outcomes

  • Sanity-powered sites are cached globally
  • Studio and preview bypass cache
  • Images can be transformed per template
  • Publish webhooks can purge immediately

Frequently asked questions

Can I cache GROQ responses?

Prefer caching the front end. If you cache GROQ, exclude draft datasets and authenticated queries.

Does this work with Sanity Image Pipeline?

You can use Sanity as the image origin and still cache the result on Cloud CDN under your hostname.

What about live preview?

Live preview must bypass cache. Only the public published hostname should be cached.

Can I use token authentication for private datasets?

Yes. Protect non-public paths with Cloud CDN token authentication in addition to origin checks.