So, it isn't clear why you experienced those events, but for the CDN, it is always recommended to use it because it is cached, so it's always faster.
The way it works is if the Prismic master ref is old, then there's a good chance that any request you make is cached. When you create a new ref, when you publish a change, and your API updates, it clears that cache.
So the first time you make any given request, it's gonna make a call to the server, and it'll run the request and come back. From that point on, if you're using the same ref and making the same request, it's gonna give you the cached version, and it'll do that for all requests.
So, using the CDN after you've done the first request of any kind, it'll be much faster to use, and it won't consume your bandwidth on the Prismic side.
I understand the benefit of the cache. But a cache is only faster after the first time, right? For a static generated website, I never have more than one API request to get the master ref (so every call is a "first" call that refreshes the cache). So the next request is when something new is published and the webhook is executed.
I am still often getting the wrong/old master ref returned from the API when I use the cdn url. I was hoping you could either fix it or tell me that it's intended behaviour Maybe it has something to do with the preview ref that is being removed at the same time as a new master ref gets generated?
2: I found out because my client didn't always see the latest published content on their website. The steps to (sometimes) reproduce:
a) Edit, save and preview a document.
b) Edit, save, publish and view.
It's like the cdn is slower at saving new content, so it sometimes isn't ready when the webhook fires.
3: I'm not caching, because I only have one api->query. and the content loaded should always be the newest.
I have made a fallback where I'm using the master ref from the webhook data, so I'm not using the master ref returned from the API::get... This has worked so far.
hope you are well. We are experiencing the same problem to @MichaelVestergaard 's point 2.
We tried to use masterRef too, we got from webhook's payload to explicitly define the ref when we initialize client with createClient() method but this yielded no results.
Has the masterRef been changed since 2022 November? If so, what's the replacement code?