Purpose of generateStaticParams in next js, and is it worth it? #73959
Replies: 1 comment 2 replies
-
Yeah that's kind of odd. I think, If its a closed set, you can serve both the content, and 404's such for non existing content, right away. No on-demand needed. If its an open set, then you can render an "important" sub set, by some heuristic, and then leave it open for on-demand generation of less "important" pages. In both cases, you can also allow for revalidation, and have 404's have its own time to be cached as well, so that is new content does appear, it'll take over the 404.
I think this section of the migration, can help you: https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#dynamic-paths-getstaticpaths to correlate both Having written all of this now, I think the claim, |
Beta Was this translation helpful? Give feedback.
-
Summary
I've been reading the next.js docs, and there are two things that puzzle me about the
generateStaticParams
.#1: 1st thing that puzzles me is the paragraph at https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes#generating-static-params .
So the primary benefit is that generateStaticParams helps other occurences of generateStaticParams, making them faster? That makes me think that it's a no brainer NOT to use generateStaticParams at all, which nullifies the build time impact completely.
#2 I understand that it also generates the route before a request has been made as well. But that's what makes me wonder.. I'll try explaining with an example:
Case 1: For our blog posts, we don't use SSG (
generateStaticParams
):As far as I know, once a dynamic route like /blog/posts/[slug] is hit, the content is generated at request time, stored in the "Full Route Cache" which is persistent, and then sent to the visitor's browser. Any visits from now on, whether it be 5 mins later or a month, will be sent from this cache. Negating the need for a re-render on server.
Case 2: We do use SSG (
generateStaticParams
):All the possible routes are generated at build time and stored at the "Full Route Cache", and any requests to them will be delivered from that cache, negating the need for a re-render on server.
Now let's say in Case 1, we had all of our blog posts visited by previous visitors. And that will cause every rendered blogpost page to be stored in the "Full Route Cache", which effectively brings it to the same state with Case 2.
So in the end, all
generateStaticParams
can do for us is just making the first ever request a little bit faster. But in return, we lost the ability to run revalidation on those routes. <-- I'm not sure about that onethe TLDR version of my questions are:
generateStaticParams
is said to be faster generation times. The alternative is not generating these pages AT ALL, which definitely results in faster build time. Am I missing a point?generateStaticParams
or not ?I might have some errors in my understanding of the concepts. If so, I apologize and would appreciate some enlightenment!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions