My build times on Vercel increased 6x when I added generateStaticParams #67471
Replies: 2 comments 6 replies
-
@JamesSingleton This would make sense depending on how many pages you generate now statically generating hundreds or thousands of pages can take several minutes to fetch, process images, load, process, save, and send the caches. I'd recommend trying putting a cap on the generation first 100 or 200 and see if the time increase is linear or not, and writing out the build time and article title to something like redis to quickly grab the data and see if there are some outliers causing the issue to begin to narrow it down. |
Beta Was this translation helpful? Give feedback.
-
Damn that's impressive, my recommendation is maybe to tier your articles so only generate the top 30% trafficked cuts down a lot on excessive pre generation and the rest can be left to ISR, it's what I plan on shipping with one site with around 4k articles. |
Beta Was this translation helpful? Give feedback.
-
Summary
I have been facing a lot of issues with Fast Origin Transfer in Vercel for a single project of mine and I reached out to @leerob on Twitter to find out a solution for taking care of this. I asked if adding
generateStaticParams
to myapp/(website)/[slug]/page.tsx
could potentially help reduce it and the answer was yes. I use Sanity CMS for all my articles which is roughly 400+ articles. Builds were previously taking 2-3 minutes to build 18 static pages, which I thought was a long time but it was whatever at the time.I introduced
generateStaticParams
to my slug page roughly 25 days ago and the last 3 deploys have taken:I was not expecting a 6x increase when adding
generateStaticParams
. I use the next-sanity library per Sanity's recommendation. I have it setup like so:My page's
generateStaticParams
looks like so:Where
getPostsPaths()
looks likeAnd that query just grabs the slug from Sanity
For the
generateMetadata()
, I use the same function that I use to populate the page, which isgetPostBySlug()
And that
postsBySlugQuery
looks like:How can I reduce these build times because it sounds like a me issue as others are building more pages and "heavier" pages in seconds. What else can I look into?
Additional information
Deps that I think would be relevant:
Beta Was this translation helpful? Give feedback.
All reactions