skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. Set Revalidation in getStaticProps:
    Use the revalidate property to specify how often you want to regenerate the page.

    export async function getStaticProps(context) {
      // Fetch your data here
    
      return {
        props: {
          // Your props here
        },
        revalidate: 60, // Regenerate the page every 60 seconds
      };
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search