ISR and generateStaticParams help
Answered
Transvaal lion posted this in #help-forum
Transvaal lionOP
In my generateStaticParams, I call an api that returns a list of slugs for pages to be built. In 24 hours- that list of slugs may change either with new entries or deleting old ones. Is there a way to re-run generateStaticParams every X hours?
Answered by Plague
Yeah you can set the dynamic route page to revalidate every 24 hours by setting
If you are able to have this API hit your own route handler via something like a webhook you can use
export const revalidate = 86000. This will revalidate the entire dynamic route (including the generateStaticParams) after the first request after 24 hours.If you are able to have this API hit your own route handler via something like a webhook you can use
revalidatePath to invalidate all the dynamic routes in that segment on demand.8 Replies
@Transvaal lion In my generateStaticParams, I call an api that returns a list of slugs for pages to be built. In 24 hours- that list of slugs may change either with new entries or deleting old ones. Is there a way to re-run generateStaticParams every X hours?
Yeah you can set the dynamic route page to revalidate every 24 hours by setting
If you are able to have this API hit your own route handler via something like a webhook you can use
export const revalidate = 86000. This will revalidate the entire dynamic route (including the generateStaticParams) after the first request after 24 hours.If you are able to have this API hit your own route handler via something like a webhook you can use
revalidatePath to invalidate all the dynamic routes in that segment on demand.Answer
Do note however, that the
export const revalidate option will NOT revalidate all dynamic routes after the first request after 24 hours, only the route that was visited.Additionally,
generateStaticParams pre-builds the pages you know exist, but, for any that may not exist they still hit the dynamic route and therefore can still render the page fine (depending on your code) just fully SSR instead of ISR.Transvaal lionOP
I see. Is it possible to have some pages SSR and others ISR?
To further to explain: If I know for sure there are slugs that will never disappear but potentially update- can i still have have generate static params and SSR the other pages?
To further to explain: If I know for sure there are slugs that will never disappear but potentially update- can i still have have generate static params and SSR the other pages?
Transvaal lionOP
So far- it looks like I can do ^
But is there any consideration towards cacheing I need to take?
But is there any consideration towards cacheing I need to take?
@Transvaal lion I see. Is it possible to have some pages SSR and others ISR?
To further to explain: If I know for sure there are slugs that will never disappear but potentially update- can i still have have generate static params and SSR the other pages?
Yup this is the default behavior of
generateStaticParams the pages you pre-build are ISR functions while the ones you don't will be fully dynamic (SSR)@Transvaal lion So far- it looks like I can do ^
But is there any consideration towards cacheing I need to take?
If you want to cache, you can cache any data fetches if that's a concern for you, if not you don't need to worry about anything else, those SSR pages will become ISR whenever it is you re-build. So they won't stay SSR forever
@Plague If you want to cache, you can cache any data fetches if that's a concern for you, if not you don't need to worry about anything else, those SSR pages will become ISR whenever it is you re-build. So they won't stay SSR forever
Transvaal lionOP
Thank you. Marked the above as a solution 🙏