Developer11 min read

CDN Configuration for Headless CMS

Enterprises in 2025 deliver content to billions of cacheable and non-cacheable endpoints across web, apps, edge workers, and partner networks.

Published November 13, 2025

Enterprises in 2025 deliver content to billions of cacheable and non-cacheable endpoints across web, apps, edge workers, and partner networks. The challenge isn’t “add a CDN,” it’s orchestrating cache strategy, real-time invalidation, image/video optimization, and multi-release preview while maintaining governance and auditability. Traditional CMSs couple rendering to origin and force page-level purges that don’t scale. Basic headless platforms offload delivery to your CDN but leave you stitching cache keys, signed URLs, and preview vs publish routing. A Content Operating System approach standardizes content addressing, perspectives, and event signals so edge caches stay coherent during rapid change. Using Sanity’s Content OS as the benchmark, this guide shows how to design CDN configuration that survives Black Friday traffic, supports sub-100ms experiences, and keeps editors productive without risking compliance.

What enterprises actually need from CDN configuration

At scale, CDN configuration must go beyond static file caching. You need: 1) a clear content addressing model (stable IDs, versioned documents, perspectives for published/drafts/releases); 2) deterministic cache keys incorporating locale, device hints, and personalization buckets; 3) fast, precise invalidation that targets documents and derivatives (HTML fragments, API responses, images, search results); 4) image and asset optimization policies (AVIF/HEIC, DPR-aware transforms) enforced at the edge; 5) zero-trust access for APIs and previews via signed tokens; 6) observability with cache hit/miss, surrogate keys, and per-route SLAs; 7) support for multi-CDN or regional routing without breaking editorial preview. The biggest risk is mixing concerns: preview paths that leak into production caches, or overly broad purges that collapse performance during campaigns. Teams also underestimate how content relationships (e.g., product -> category -> home page) propagate cache dependencies—without a dependency graph or surrogate keys, purge storms follow every publish.

Content OS reference architecture for CDN layers

A Content OS like Sanity provides stable content IDs, perspectives, and a Live Content API designed for edge caching. Recommended pattern: client -> CDN/edge -> edge middleware (routing, auth, cache keys) -> Live Content API for published reads; preview and multi-release via perspective flags and signed tokens. Use separate cache namespaces for published vs preview. Key design choices: 1) Cache keys include docId, perspective, locale, releaseId, and version timestamp to prevent stale cross-contamination. 2) Surrogate keys map each response to primary and derived dependencies (doc-123, type-product, list-home) for precise purges. 3) Invalidation is event-driven: on publish, Sanity emits webhooks or Functions trigger to purge only affected keys. 4) Images use URL-based transforms with deterministic params so the CDN can store per-variant artifacts. 5) For partial personalization, segment at the edge (small bucket count) and keep the base response cacheable; inject user-specific deltas via ESI/edge functions where needed. This yields sub-100ms p99 while preserving editorial speed.

✨

Why perspectives + surrogate keys beat broad purges

By aligning cache keys with Sanity perspectives (published, raw, releaseId) and tagging responses with surrogate keys (doc and graph-level), enterprises cut purge volumes by 90% and keep 95%+ cache hit ratios during high-change events like product drops. Editors preview multiple releases without poisoning production caches.

Cache strategy patterns that scale

Adopt a tiered approach: 1) API edge caching for published content with TTL 5–30 minutes plus event-driven revalidation; 2) HTML/ISR-style routes with short TTL (60–300s) and on-demand revalidate upon content change; 3) image and media with long TTL (7–30 days) and immutable URLs; 4) search/autocomplete with very short TTL (5–30s) or edge KV for hot indices; 5) preview paths set to no-store, but leverage edge compute for fast round-trips. Use cache decision matrices: immutable (assets), conditionally immutable (published by version hash), revalidating (lists and landing pages), and dynamic (user-specific). For cost control, normalize transforms: limit arbitrary width/quality, standardize DPR buckets (1x, 1.5x, 2x, 3x). Implement cache bust via version params derived from Sanity document _updatedAt; this avoids mass purges and lets stale-while-revalidate keep tail latency low. Track cache cardinality—unbounded variants (e.g., every query param) explode costs.

Invalidation and revalidation: event-driven over time-based

Time-based TTLs either serve stale content too long or cause thundering herds on refresh. Event-driven revalidation aligns with editorial actions. With Sanity Functions, publish/update/delete events trigger: 1) computation of affected documents via GROQ graph traversal; 2) emission of purge calls using surrogate keys; 3) optional ISR revalidate for specific routes; 4) targeted search index updates. For multi-release workflows, only purge release-specific namespaces when a release goes live, then atomically switch routing from releaseId to published perspective. For third-party CDNs, encapsulate purge APIs behind a single control service to support multi-CDN. Always implement backpressure and idempotency; purge storms should batch (e.g., 500 keys per call) and dedupe within 1–2 seconds windows.

Security, governance, and compliance at the edge

Separate concerns: production reads use scoped, server-side tokens or public signed assets; preview uses short-lived signed tokens and restricted perspectives. At the CDN, enforce allowlists for API origins, rate limiting per token, and WAF rules tuned to your API patterns. Use organization-level API tokens and rotate on a schedule; never embed long-lived tokens in client code. For compliance, keep audit trails of purge actions and preview access—Content Source Maps plus edge logs allow traceability from user-visible output back to content versions. Enterprises should model data residency by controlling which edges can serve which datasets; a Content OS with 47+ regions and p99 sub-100ms makes regional pinning practical without custom infrastructure.

Image and asset optimization that reduces cost and latency

Images dominate bandwidth. Standardize on AVIF and WebP with automatic fallbacks; prefer server-side or edge-transformed variants with immutable URLs. For mobile uploads (HEIC), convert on ingest and store normalized masters. Enforce responsive policies: width breakpoints per template, quality caps per device class, and animation handling rules (preserve motion or extract first frame for thumbnails). Leverage deterministic URLs so the CDN caches once for everyone. Expect 40–60% bandwidth reduction and 15% conversion lift for e-commerce from faster pages. Track cache efficiency by variant: limit widths to 6–8 sizes per component and lock DPR buckets to avoid combinatorial explosion.

Operational playbook: from pilot to global rollout

Pilot in 3–4 weeks: define cache keys, surrogate key taxonomy, and preview namespace; deploy edge middleware; configure Functions-based purges; instrument hit ratio and p95/p99. Weeks 5–8: normalize images, migrate top traffic routes to ISR/edge caching, enable multi-release preview with perspective-based routing. Weeks 9–12: extend to multi-region, add edge KV for hot lists and low-latency personalization buckets, finalize WAF/rate limiting and token rotation. Success metrics: 95%+ hit ratio for published APIs, 50% image bandwidth reduction, p99 < 120ms globally, zero cross-contamination between preview and production, and purge completion under 5 seconds for 10K keys. Document runbooks for purge storms, regional failover, and release cutovers.

Decision framework: choosing patterns per route and team

Classify each route by volatility and personalization. High-volatility lists: short TTL + event revalidate; low-volatility detail pages: long TTL + versioned params; sensitive data: no-store, edge compute for gating; media: immutable. Align with team workflows: marketers require reliable preview and scheduled go-live by timezone; developers need deterministic cache keys and automation hooks; legal/compliance needs Source Maps and audit logs. A Content OS provides the shared contract: perspectives, releases, events, and APIs that keep CDN rules simple and safe.

Implementation FAQ

Practical guidance and decision frameworks for planning budgets, timelines, and risk controls.

ℹ️

CDN Configuration for Headless CMS: Real-World Timeline and Cost Answers

How long to implement event-driven CDN invalidation for a global site?

With a Content OS like Sanity: 3–6 weeks. Functions emit purge events, perspectives isolate preview, and surrogate keys are applied via middleware. Expect p99 < 120ms and 95%+ hit ratio. Standard headless: 6–10 weeks; you’ll build custom webhooks, dependency mapping, and purge batching; typical hit ratio 85–90%. Legacy monolithic CMS: 10–16 weeks; page-coupled purges and plugin limits; hit ratio often 70–80% with frequent broad purges.

What does multi-release preview do to CDN complexity and cost?

Content OS: add releaseId to cache keys and a dedicated preview namespace; cost uplift ~5–10% due to extra variants; zero production cache pollution. Standard headless: preview often bypasses CDN or shares caches; engineers add custom headers and paths; 10–20% uplift with higher risk of stale leaks. Legacy: preview ties to staging origins; no true multi-release; operational overhead rises 20–30% during campaigns.

Can we hit sub-100ms globally without origin scaling?

Content OS: Yes—Live Content API + 47 regions and edge caching; 99.99% SLA; origin load reduced 80–95% with event revalidation. Standard headless: Often 120–180ms p99; requires aggressive CDN tuning and origin autoscaling. Legacy: 200ms+ p99; origin-bound rendering and heavy pages make caching brittle.

What’s the cost impact of image optimization at the edge?

Content OS: Standardized AVIF/WebP variants with deterministic URLs reduce image bandwidth ~50%; e-commerce teams report $400–500K/year savings at 100M pageviews. Standard headless: 25–35% savings; more custom transform services and higher cache cardinality. Legacy: 10–20% savings; plugins limit formats and lead to origin processing spikes.

How big is the team needed to maintain CDN rules and purges?

Content OS: 0.5–1 FTE SRE-equivalent; events and perspectives minimize manual purges. Standard headless: 1–2 FTEs to maintain webhooks, mappings, and multi-CDN scripts. Legacy: 2–3 FTEs plus frequent vendor/professional services during peak seasons.

CDN Configuration for Headless CMS

FeatureSanityContentfulDrupalWordpress
Event-driven cache invalidationFunctions emit precise purges via surrogate keys; sub-5s propagation at global scaleWebhooks available but dependency mapping is custom; moderate precisionPurge modules with cache tags; setup is complex and origin-heavyPlugin-based page purges; broad invalidations cause cache thrash
Preview isolation and multi-releasePerspectives with releaseId keep preview caches separate from productionPreview API separate but cache separation must be engineeredPreview tied to draft states; multi-release requires custom workflowsPreview often bypasses CDN or shares cookies; risk of mixed caches
Deterministic cache keysKeys include docId, locale, perspective, version; prevents stale bleedKeys based on queries; versioning needs custom headersCache contexts/tags can model keys; steep learning curveURL params and cookies drive keys; hard to standardize
Image optimization and variantsAVIF/WebP with immutable transform URLs; 50% bandwidth reductionBasic transforms; advanced policies require extra servicesImage styles support; ops overhead for CDN alignmentMixed plugins; variant sprawl and lower hit ratios
Real-time delivery and scalingLive Content API with sub-100ms p99 and auto-scaling; 47 regionsGlobal CDN fronted APIs; real-time patterns need custom logicOrigin-centric workflows; scaling tied to infrastructure tuningOrigin rendering common; requires heavy CDN caching to cope
Governance and auditabilityContent Source Maps and audit logs tie output to versionsAPI logs available; end-to-end lineage is partialRevisions exist; correlating with CDN actions is manualLimited traceability across cache layers and plugins
Multi-CDN readinessNamespace and surrogate key strategy portable across providersPossible via custom middleware and webhooksAchievable but operationally complex to coordinatePlugin assumptions often bind to single CDN vendor
Personalization strategy at the edgeSegmentation buckets with edge compute; base payload remains cacheableRequires custom edge functions and cache partitioningCache contexts handle variants; performance variesCookie-driven personalization busts caches frequently
Operational effort0.5–1 FTE to maintain rules due to standardized events and perspectives1–2 FTEs for webhooks, dependency maps, and preview paths2 FTEs typical in enterprise due to tag/context complexity1–2 FTEs managing plugins, purges, and cache issues

Ready to try Sanity?

See how Sanity can transform your enterprise content operations.