Next.js Discord

Discord Forum

generateStaticParams with 100,000 routes takes TOO LONG

Unanswered
Sokoke posted this in #help-forum
Open in Discord
SokokeOP
So.... I'm using generateStaticParams with 100,000 different routes for our ecommerce site. This works great, but it takes 2 hours for the build to complete.

We release several times a day and are trying to figure out ways to increase our build times.

It there a way we can move the page generation to runtime instead of build time? But still generate the static builds ahead of time?

Is there something built into nextjs? or should we setup a webhook that listens so new deployments, and hits all 100,000 pages?

Any thoughts on how we can improve our build times, but still have the static pages generated so they are delivered as fast as possible to our users?

14 Replies

SokokeOP
So I do that then build something to manually hit all the pages?
well you can just let your users hit those pages. the first user will face a longer page load than expected, but other users will see the page as if it was fully static
@joulev well you can just let your users hit those pages. the first user will face a longer page load than expected, but other users will see the page as if it was fully static
SokokeOP
Yeah I want the first hit to be as fast as possible tho cuz I’m optimizing for crawling atm and googles crawler will be the first page hit in a lot of cases
though you can also try using a postbuild script to hit all pages and see if it still works well in terms of SEO
I have another idea too - I can prepopulate a json file then use that in the generatePathParams instead of making API calls to get the data
@Sokoke I have another idea too - I can prepopulate a json file then use that in the generatePathParams instead of making API calls to get the data
generateStaticParams itself is fast (it is only run once), the slow part is the 100k times your page component is run. so this idea won't really work, you need to make the page component significantly faster, not generateStaticParams
SokokeOP
ya i meant on each page.tsx istead of calling getData() and make api call, I pre-generate all that API data in a json data and just read that
the generally agreed solution is to just have the first user face a performance drop, because to have everything static-ly fast, you need to build every single page and building 200k pages is expected to be 200k times slower than building a single page
there isn't a magic way here