👀 See Sanity in action: Watch product demo now →

Enabled useCdn:true Not Working for Sanity API CDN with React

15 replies
Last updated: Jun 23, 2022
Hello Team, I wanted to use Sanity API CDN in my React Project. I'm using @sanity/client in the project. As document suggested I enabled useCdn:true but in the URL I check it is still using api.sanity.io instead if cdnapi.sanity.io please kindly help me in this how to use the CDN with React
Jun 23, 2022, 2:17 PM
Do you use a token with your client?
Jun 23, 2022, 2:20 PM
Yes. I used
Jun 23, 2022, 2:21 PM
What all parameters in config should I have to enable CDN ?
Jun 23, 2022, 2:22 PM
Nope, not with a token. 🙂
Jun 23, 2022, 2:22 PM
This causes requests to be authenticated, which bypasses the CDN.
Jun 23, 2022, 2:23 PM
So, should I use token or not ?
Jun 23, 2022, 2:24 PM
Is your dataset public or private? If your dataset is private, you can only query data with a token. Because that‘s essentially authentication.
Jun 23, 2022, 2:24 PM
If your dataset is public, you don’t need a token. You can just read data without it. You’d need it to write data though.
Jun 23, 2022, 2:25 PM
This is my config file
Jun 23, 2022, 2:25 PM
My dataset is not a public
user F
so, using token
Jun 23, 2022, 2:28 PM
Right. So no CDN I’m afraid.
Jun 23, 2022, 2:28 PM
user F
useCdn:true will bypass it to Sanity CDN but why I'm seeing url api.sanity.io
Jun 23, 2022, 2:42 PM
No,
useCdn
will not work with a token. That’s what I meant. 😄
Jun 23, 2022, 2:44 PM
Jun 23, 2022, 2:44 PM
okay
user F
Thanks a lot🙏😃
Jun 23, 2022, 2:52 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.