Join our next Developer Virtual Meetup – Live Q&A, Project Showcase, Swag raffle, and more πŸ”₯

Discussion on cache problem and webhook usage for updating blog posts on Nextjs hosted on Vercel with Sanity.io.

12 replies
Last updated: Jan 7, 2021
Hello. I believe I have some sort of cache problem. I have a blog on Sanity and when I create or edit blog posts I can see the update instantly when I publish it on local but it takes close to 5-10min to appear on production. Ultimately it does appear but I'm wondering why this is happening.My blog is on Nextjs, hosted on Vercel.
Jan 6, 2021, 9:41 PM
Oh. Do I have to create some sort of webhook to force a ploy every time there's a published update?
Jan 6, 2021, 9:45 PM
Depends how you're fetching your data from Sanity. If you're using getStaticProps without revalidate, you'll need to deploy on Vercel after making a change. If you're using revalidate or fetching via getServerSideProps, getPromise, etc., you shouldn't need to redeploy.
As for the 5-10 mins, that's probably due to
useCdn: true
when you configure your sanityClient.
Jan 6, 2021, 10:09 PM
Thanks for your reply
user A
. It's now working with a webhook from Vercel.
Jan 6, 2021, 10:23 PM
Nice! πŸŽ‰
Jan 6, 2021, 10:26 PM
It actually take 2 deploys to actually update the content with a webhook. Do you think this is because of the CDN?
Jan 6, 2021, 10:37 PM
Ah yes apparently. I'll try without to see how it goes.
Jan 6, 2021, 10:39 PM
You would want to set
useCdn: false
.
Jan 6, 2021, 11:17 PM
In case
useCdn: false
doesn't work: there might be a slight sync delay between when the webhook is fired and when the data is available from the API. You could consider calling a serverless function instead, which then calls the Vercel deploy hook after a short timeout to prevent having to do 2 deploys πŸ™‚
You might not need the webhook though, as Geoff suggested above.
Jan 7, 2021, 9:07 AM
Ah very true. I changed the request to be on every render server side and it works great. For some reason most example out there on Nextjs uses getStaticProps so I assumed it was best practice but it's much easier to do it per render to avoid having to do too much work on webhooks.
Jan 7, 2021, 10:20 AM
(Heads up: keep an eye on your API request usage statistics in case things need to be more frugal πŸ™‚)
Jan 7, 2021, 10:30 AM
Will do. Yes I can see it being a problem with higher traffic. We are fairly small for now so all good.
Jan 7, 2021, 10:31 AM
Will do. Yes I can see it being a problem with higher traffic. We are fairly small for now so all good.
Jan 7, 2021, 10:31 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?