Next.js Discord

Discord Forum

Static generation for unknown path

Answered
Large oak-apple gall posted this in #help-forum
Open in Discord
Avatar
Large oak-apple gallOP
My app has some pages that I hardcoded and some that user might add later using top level ./[path]/page.
Might be challenging to know which path name user will assign to include it into generateStaticParams, but I still want to make this page static.
Is it possible?

Making it dynamic on first request and static on subsequent requests is acceptable, as long as timed and manual revalidation still works for them
Answered by B33fb0n3
yes, you can do that: first dynamically rendered and later statically rendered. It's called [ISR](https://nextjs.org/docs/canary/app/building-your-application/data-fetching/incremental-static-regeneration).

With that you can build many pages (that you know) during build time and the ones that you don't know will be statically generated when someone access them. While accessing, they will be created and saves (cached) for the next person. The next person then gets the generated html instantly
View full answer

7 Replies

Avatar
yes, you can do that: first dynamically rendered and later statically rendered. It's called [ISR](https://nextjs.org/docs/canary/app/building-your-application/data-fetching/incremental-static-regeneration).

With that you can build many pages (that you know) during build time and the ones that you don't know will be statically generated when someone access them. While accessing, they will be created and saves (cached) for the next person. The next person then gets the generated html instantly
Answer
Avatar
Large oak-apple gallOP
What is required for that to work like this? Just export const revalidate ?
Avatar
you just need these three things: (see attached) and then configured to your needs
Image
Avatar
Large oak-apple gallOP
But this whole issue comes from not knowing data to use in function. If I knew, I would simply generate pages at build time like usually
Avatar
you can build many pages (that you know) during build time and the ones that you don't know will be statically generated when someone access them. While accessing, they will be created and saves (cached) for the next person. The next person then gets the generated html instantly
Avatar
Large oak-apple gallOP
I see, thanks
Avatar
sure thing