useCDN set to true but still getting CDN warning in Next.js build

18 replies
Last updated: Jan 28, 2026
Hi all, I feel like I’m missing something super obvious regarding the CDN.
I’ve set
useCDN: true
and yet when I build, it still gives me the warning that I’m not using the CDN.
const options = {
	projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
	dataset: process.env.NEXT_PUBLIC_SANITY_DATASET_NAME,
	apiVersion: "2022-01-18", //date project was initialized
	useCDN: process.env.NEXT_PUBLIC_SANITY_DATASET_NAME === "production", <= results in true
};
When I inspect my site, I see the images have an address which includes
<http://cdn.sanity.io|cdn.sanity.io>
What am I missing?
AI Update

I can see the issue here! Based on the official API CDN documentation, the warning you're seeing is likely not related to authentication at all. Here's what's actually happening:

Your Images ARE Using the CDN

You correctly noticed that your images are loading from cdn.sanity.io - that's the Asset CDN, which always works through the CDN regardless of your client configuration.

The Build-Time Warning is Expected

When you run next build (or similar build commands), you're generating static content. During static builds, you should NOT use the CDN - you want the freshest data possible to build your pages. The warning is actually helpful here because it's reminding you that build-time queries should hit the live API, not the cached CDN.

The useCDN option controls whether your GROQ/GraphQL data queries use the cached API CDN (apicdn.sanity.io) or the live API (api.sanity.io).

About Authenticated Requests and the CDN

One important clarification: The API CDN documentation explicitly states that authenticated requests ARE cached on the CDN. They're just "segmented for each unique authentication token." So if you have a token in your client config, it will still use the CDN when useCDN: true is set.

Your Configuration is Actually Correct

Your setup looks good:

const options = {
  projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
  dataset: process.env.NEXT_PUBLIC_SANITY_DATASET_NAME,
  apiVersion: "2022-01-18",
  useCDN: process.env.NEXT_PUBLIC_SANITY_DATASET_NAME === "production", // ✅ Good
};

For production runtime: useCDN: true means browser requests will use the fast, cached CDN
For build time: The warning reminds you that builds should use fresh data

Note on the Option Name

The property name is useCdn (lowercase 'n'), not useCDN. While many JavaScript clients accept both due to case-insensitive handling, the canonical form is useCdn. If you're seeing a warning specifically about the casing, try changing:

useCDN: true  // might cause a warning

to:

useCdn: true  // canonical form

When You Actually See CDN Usage

The CDN is used for:

  • Client-side queries when useCdn: true
  • Image assets (always)
  • Runtime data fetching in browsers

The CDN is NOT used for:

  • Build-time queries (intentionally, to get fresh data)
  • Server-side rendering in some frameworks (depends on configuration)

Your setup is working correctly - the images are on the CDN, and your production client will use the API CDN for data queries at runtime. The build warning is just informing you that during the build process itself, you're hitting the live API for the freshest content.

Show original thread
18 replies

Sanity – Build the way you think, not the way your CMS thinks

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.

Was this answer helpful?