Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

Client API CDN configuration

Sanity provides a CDN-distributed, cached API that is faster and cheaper to use. A full explanation of the differences between these APIs are outlined on the API CDN documentation.

The Sanity JavaScript client can easily be configured to use either of the APIs by setting the useCdn option to true or false when creating the client:

const SanityClient = require('@sanity/client')
const client = new SanityClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  useCdn: true

Note that the client will automatically fall back to using the live API in the following scenarios:

  • When a mutation is performed (creating/editing/deleting documents)
  • When listeners are used (subscribing to changes)
  • When the token option is specified when creating the client
  • When the withCredentials option is specified when creating the client

Was this article helpful?