How to add new pages without rebuilding an app with +150k static pages?

I have a MERN app in which I have integrated NextJS. First time with NextJS so bear with me. I have initially used SSR everywhere (getServerSideProps).

Key points:

  • I have over 150,000 pages with static content that it's never going to change.
  • Every week I add around +100 new pages.

I guess the ideal situation here would be using getStaticProps and getStaticPaths and, after an initial build of those 150k pages, just build the new added pages every week and keep what I already have built as it is since it's never going to change.

How can I achieve this? Should I use revalidate here? I have been reading about it in the documentation but I don't completely understand it.


Solution 1:

That can be achieved with getStaticProps/getStaticPaths. You'll have to use fallback: true or fallback: 'blocking' in getStaticPaths.

With fallback: true the paths not generated at build time will serve a fallback page on the first request while Next.js statically generates the page. When this is done the page will be swapped from the fallback page to the actual full page.

With fallback: 'blocking', the paths not generated at build time will wait for the HTML to be generated by Next.js, then serve the page once that's done. Unlike fallback: true, since there's no fallback the rendering gets blocked until the page is generated, similar to what happens during server-side rendering.

In both cases the page gets added to the list of pre-rendered pages. Subsequent requests to the same path will serve the pre-generated page.

Neither of these options is supported by next export, in case you depend on that.


Note that revalidate is used in getStaticProps for Incremental Static Regeneration - in cases where you'd want to update existing, generated pages. Since you mentioned generated pages will never change, then there's no need to use revalidate.