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
- Static Site Generation (SSG): Replace
getServerSidePropswithgetStaticPropsandgetStaticPaths. Pages compile into static HTML at build time with zero server rendering per request, though anything reading requestquery,cookies, orheadershas to move client-side and large page counts slow down builds. - Incremental Static Regeneration (ISR): Add
revalidate: <seconds>togetStaticProps(even as low as1second if you want near-SSR freshness). Concurrent traffic still hits the static cache at full speed while stale pages refresh in the background. - 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.