My application takes too long to build, since there are about 300k pages to build on build time.
It also means that I am reaching my cloud provider high limit of 1 hour per build.
I am thinking about alternative solution, like building the cache after the application starts.
Or another option is that after the application starts it will do a fetch call to my server, that will call the revalidate client api with the 300k routes to build / revalidate.
Is there a different solution that might work? and if not how can I do one of the following? I couldn’t find a way to call function on start without involving webpack, or a way to make getStaticPaths happened after start instead of build time.
2
Answers
I did not find an option within Next.js ecosystem for now. The only solution that I found is with my cloud provider (Digital Ocean), there is an option to trigger a "job", after the deployment finishes.
So I made a script that do a fetch request to my Next.js API route. That API Route takes an array of url paths and revalidate them in batches. I am not sure the batch size matter that much since it's just Promise.all, I put the batch size at 50 and it works fine so far.
Set Revalidation in getStaticProps:
Use the revalidate property to specify how often you want to regenerate the page.