Sitemap indefinitely cached Vercel (Next.js 13 app router)
Unanswered
Oak shoot sawfly posted this in #help-forum
Oak shoot sawflyOP
I have a sitemap.ts that makes a fetch call to a CMS to get pages to show in the sitemap. The fetch call has a cache tag associated with it that is revalidated.
However, my sitemap is not getting new pages that are added to the CMS. All other cache revalidation tags work, but the sitemap one specifically does not. Rebuilding and deploying does update the sitemap.
I have seen others having similar issues, but couldn't find an answer. Is there a fix or approach for this?
However, my sitemap is not getting new pages that are added to the CMS. All other cache revalidation tags work, but the sitemap one specifically does not. Rebuilding and deploying does update the sitemap.
I have seen others having similar issues, but couldn't find an answer. Is there a fix or approach for this?
6 Replies
Oak shoot sawflyOP
export const dynamic = 'force-dynamic'; on the sitemap file works, but then I'm missing out on cache entirelyOak shoot sawflyOP
Explicitly setting
export const revalidate = 60 also works, but it's not ideal. It would be better to revalidate the sitemap on demand using cache tags like I've used elsewhere as it would reduce calls to my CMS and also keep the sitemap up-to-date rather than 60 seconds@Oak shoot sawfly Explicitly setting `export const revalidate = 60` also works, but it's not ideal. It would be better to revalidate the sitemap on demand using cache tags like I've used elsewhere as it would reduce calls to my CMS and also keep the sitemap up-to-date rather than 60 seconds
have you tried
revalidatePath? like revalidatePath("/sitemap.xml") if that sitemap is saved to /sitemap.xml. i haven't tried but it's worth trying thisOak shoot sawflyOP
That seems to work. Any idea why revalidating the path would work but revalidating the tag for the fetch doesn't? Does Next have some specific path level caching for sitemap?
@Oak shoot sawfly That seems to work. Any idea why revalidating the path would work but revalidating the tag for the fetch doesn't? Does Next have some specific path level caching for sitemap?
revalidating the tag for the fetch should work too, i'm surprised to hear that
you may want to report a bug