🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Discussion about using the correct CDN for assets in Sanity and potential issues with multiple requests for the same asset.

13 replies
Last updated: Nov 30, 2022
Noticing during a component refresh network traffic is fetching the same asset multiple times. I found this to use apicdn.sanity.io instead of api.sanity.io https://www.sanity.io/docs/api-cdn
Currently we are using this dependency
https://sanity.nuxtjs.org/getting-started/quick-start and setting
useCDN: true
but what it's using instead is cdn.sanity.io ? Is there a difference between cdn & apicdn??
I think also we need to adjust the time for "Stale while revalidate" to cache an asset for longer
Nov 29, 2022, 10:25 PM
Noticing during a component refresh network traffic is fetching the same asset multiple times
Would you be able to provide an example of what you’re seeing?

what it’s using instead is cdn.sanity.io ? Is there a difference between cdn & apicdn?
The
useCdn
property is only for document requests (API vs. API CDN), while assets will always use
<http://cdn.sanity.io|cdn.sanity.io>
(and aren’t impacted by that property). There are some more details about the API and API CDN .
Nov 30, 2022, 12:24 AM
In this screenshot these are the same file 206 but not saying (from disk cache). We had a crazy spike in bandwidth last wednesday. idk if it kept requesting videos all day on someone's machine? my best guess
But okay, so the asset.url provided as "cdn.sanity" is expected
Nov 30, 2022, 12:32 AM
I’m probably using the wrong terminology, but could each of those requests be a chunk as part of the complete file?
Nov 30, 2022, 12:33 AM
Looks like 206 is a partial content status, which would seem to align with that.
Nov 30, 2022, 12:34 AM
Do the response headers include any sort of start and end metrics that you could analyze?
Nov 30, 2022, 12:34 AM
I think you're right
Nov 30, 2022, 12:34 AM
i'm not sure, tbh where to look - response tab isn't providing anything
Nov 30, 2022, 12:36 AM
Hmm… me neither. 😅
Nov 30, 2022, 12:39 AM
haha whale I did update everywhere to strictly use cdn and hard refresh - i don't see network traffic for videos anymore and they are playing just fine. Sorry it's been a long day
Nov 30, 2022, 12:40 AM
Oh, great!
Nov 30, 2022, 12:41 AM
I think we're okay. Keeping an eye on it, thanks!
Nov 30, 2022, 12:41 AM
To finish off that previous thought, it looks like you would only expect multiple requests with a 206 status if the content-type were multipart/byteranges. If you’re seeing the type, then the whole thing is in one range, and 206 has something to do with resuming interrupted downloads.
In any event, do let us know if it crops up again.
Nov 30, 2022, 12:43 AM
Definitely it appears what you're saying aligns with what I'm seeing. I'll ping you in this thread if our bandwidth spikes again. Appreciate it!
Nov 30, 2022, 12:45 AM

Sanity– build remarkable experiences at scale

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

Was this answer helpful?