Next.js Discord

Discord Forum

auto generate sitemap

Answered
Sweat bee posted this in #help-forum
Open in Discord
Sweat beeOP
We have a sitemap which gets its pages from two different headless cms systems (one for the page, one for a blog). How can we automatically regenerate the sitemap if something changes, ie. a site gets published or unpublished. Nextjs has the revalidate function for the app itself, is there something similar for the sitemap generation?
Answered by Ray
export const dynamic = 'force-dynamic'
or
export const revalidate = 30
View full answer

41 Replies

export const dynamic = 'force-dynamic'
or
export const revalidate = 30
Answer
Sweat beeOP
yes we are using sitemap.ts in app folder
what does dynamic do?
@Sweat bee what does dynamic do?
it will make the sitemap render on request time
Sweat beeOP
uuh
thats interesting
and export const revalidate = 30 revalidates it every 30 minutes?
30 second
Sweat beeOP
ah ok
what would you recommend?
depend on how large your sitemap is
and how often the data are updated
but I would recommend dynamic over revalidate
Sweat beeOP
large is a matter of opinion 🙂
maybe a couple thousand sites
because revalidate happen when request come in
@Sweat bee maybe a couple thousand sites
its fine a sitemap can contain up to 50000 record
Sweat beeOP
ok but what if a site gets deleted
the first one who gets the 404 will trigger the revalidate then?
@Sweat bee ok but what if a site gets deleted
if a record get deleted?
Sweat beeOP
a lot of pages are being generated by projects... if the project dies the site is gone
how will the sitemap know
its depend on how are you generating the sitemap
if the site is gone, you shouldn't include it in sitemap
Sweat beeOP
when I do it dynamic
dynamic means on request but when the page cannot be requested anymore I get the 404
will this revalidate the sitemap and remove the page from it?
who get 404?
Sweat beeOP
the user
a user get 404 from the site do nothing to sitemap
the sitemap only revalidate when crawler trying to access it if you set a timer on revalidate
and the first request will show stale data, the new data will show on next visit
Sweat beeOP
aaah ok
I think I am gonna try dynamic and test it...
big thanks
np
Sweat beeOP
btw., is this officially documented somewhere? I barely find infos about this...
Sweat beeOP
thx