When you serve thousands or millions of dynamic entity pages, pre-rendering every URL at build time is too slow, while pure SSR hits your backend on every single request. Exploring Next.js static rendering gives you a progressive path from SSG to ISR to request-time pre-rendering.

The three stages

  1. Static Site Generation (SSG): Replace getServerSideProps with getStaticProps and getStaticPaths. Pages compile into static HTML at build time with zero server rendering per request, though anything reading request query, cookies, or headers has to move client-side and large page counts slow down builds.
  2. Incremental Static Regeneration (ISR): Add revalidate: <seconds> to getStaticProps (even as low as 1 second if you want near-SSR freshness). Concurrent traffic still hits the static cache at full speed while stale pages refresh in the background.
  3. On-demand pre-rendering (paths: [] + fallback: "blocking"): Skip pre-rendering thousands of pages during CI builds, render each page on its first live request, and serve subsequent concurrent requests from static cache.

On-demand ISR setup:

export async function getStaticPaths() {
  return {
    paths: [],
    fallback: "blocking",
  };
}

export async function getStaticProps({ params }) {
  if (process.env.CI_PIPELINE === "true") {
    return { notFound: true };
  }

  return {
    props: { /* ... */ },
    revalidate: 60,
  };
}

One Docker gotcha to watch out for: the runtime node user must own /app/.next/server/pages (chown -R node:node and writable permissions) so Next.js can write newly generated ISR HTML and JSON files to disk at request time.