
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeTo make your query use the CDN, you need to change the domain from api.sanity.io to apicdn.sanity.io. Here's the updated version:
// Compose the URL for your project's endpoint and add the query
let URL = `https://${PROJECT_ID}.apicdn.sanity.io/v2021-10-21/data/query/${DATASET}?query=${QUERY}`The key difference is using apicdn.sanity.io instead of api.sanity.io.
When you use Live CDN (also called API CDN), you get:
The CDN uses a stale-while-revalidate strategy with 600 seconds (10 minutes) cache time. This means content may be up to 10 minutes old in exchange for significantly better performance and robustness. If your application absolutely needs the freshest data on every request, stick with api.sanity.io.
If you're using the Sanity JavaScript client, you can simply set useCdn: true in your configuration instead of manually changing URLs:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
useCdn: true, // Enable the CDN
apiVersion: '2021-10-21'
})This is the recommended approach as it handles the URL construction for you.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store