Static Site Generation (SSG)
Master Static Site Generation in Next.js — pre-building pages at deploy time for maximum performance, CDN delivery, and zero server costs.
Last reviewed: January 2025
🔍 What Is It?
Static Site Generation (SSG) pre-renders pages to HTML at build time (next build). The HTML files are:
- →Stored and served from a CDN
- →Identical for every user (no personalisation)
- →Blazing fast — no server processing per request
- →Infinitely scalable — CDN handles any traffic spike
In the App Router, SSG is the default. A route is static unless it:
- →Reads
cookies()orheaders() - →Uses
searchParams - →Calls
fetchwithcache: 'no-store' - →Exports
dynamic = 'force-dynamic'
For dynamic routes (/blog/[slug]), use generateStaticParams to tell Next.js which slugs to pre-build.
🎯 Why Do We Need It?
SSG is the fastest possible way to serve web content:
- →No server cost per request — CDN serves a file, no compute needed
- →Sub-50ms response times — CDN edge nodes are geographically close to users
- →Infinite scalability — CDN absorbs traffic spikes without autoscaling
- →No database at request time — database is only queried at build time
- →Perfect SEO — full HTML available for crawlers immediately
For content that doesn't change per user (marketing pages, blog posts, docs, product listings), SSG is almost always the right choice.
🏗️ What Happens in Real Projects?
SSG in a real e-commerce platform:
- →
/— homepage with featured products (SSG, rebuilt on deploy) - →
/products— product listing (SSG + ISR, revalidated hourly) - →
/products/[slug]— each product page (SSG with generateStaticParams) - →
/blog— blog listing (SSG, rebuilt on new post) - →
/blog/[slug]— each blog post (SSG, rebuilt on edit) - →
/about,/pricing,/contact— pure static HTML
A large e-commerce site might pre-build 500,000 product pages. Next.js handles this with parallel build workers.
⚙️ How It Works
SSG build pipeline:
next buildstarts- Next.js identifies static routes (no dynamic dependencies)
- For dynamic routes, it calls
generateStaticParamsto get all slugs - It renders each route as an async Server Component, fetching data
- Outputs HTML files + RSC payloads for each route
- At runtime, CDN serves the pre-built files instantly
generateStaticParams:
export async function generateStaticParams() {
const products = await db.product.findMany({ select: { slug: true } });
return products.map((p) => ({ slug: p.slug }));
}Next.js calls this at build time to know which dynamic routes to pre-render.
💻 Example
SSG with Dynamic Routes — Pre-building a blog with dynamic slugs using generateStaticParams.
🤔 Common Confusions
❓ Does SSG mean I cannot have any dynamic content on the page?
SSG pre-builds the server-rendered HTML. You can still have Client Components with dynamic content (fetched client-side after page load). The pattern: SSG for the static shell + Client Component for user-specific data. Example: a product page (SSG) with a personalised "Recently Viewed" section (client-side fetch).
❓ What happens if a product is deleted after SSG builds the page?
The stale page will still be served until the next build or ISR revalidation. Add a notFound() check in the component — if the product no longer exists in the DB, return notFound(). With ISR, the page will be updated within the revalidation window.
❓ How long does SSG take for large sites?
Next.js parallelises SSG across CPU cores. A site with 10,000 pages typically builds in 2–5 minutes. For 1M+ pages, use ISR instead — pre-build only the most popular pages and generate the rest on first request.
🚨 Common Production Issues
Build time explosion — pre-building 100,000+ pages can take 30+ minutes. Solution: use ISR with dynamicParams = true, pre-build only the top 1,000 most-visited pages, and generate the rest on demand.
Stale content after CMS updates — SSG pages do not update until the next build. Solution: use ISR with revalidate, or configure your CMS to trigger a rebuild webhook on publish.
generateStaticParams fetching too much data — fetching full product objects when you only need slugs wastes build time and memory. Always select only the fields needed: { select: { slug: true } }.
✅ Best Practices
Use SSG as the default for all non-personalised content
Use generateStaticParams with { select: { slug: true } } — only fetch the fields needed for params
Set dynamicParams = true for large catalogs — pre-build popular pages, generate the rest on demand
Combine SSG with ISR for content that changes — pre-built but refreshed in the background
Use generateMetadata alongside generateStaticParams for per-page SEO metadata
🏛️ Architect's Note
The default-static architecture of the App Router is one of its most important design decisions. By making static the default and dynamic the opt-in, Next.js nudges teams toward the most performant architecture automatically.
For enterprise: think of SSG as your content CDN layer. Marketing sites, documentation, product catalogs — these should be 100% static. Only the authenticated, personalised parts of your app need SSR. This separation dramatically reduces infrastructure costs and improves global performance.
💬 Frequently Asked Questions
🎯 Key Takeaways
🔗 Related Topics
🎯 Practice this topic in interviews
↗ Where this topic fits
Next.js Technology Guide
Return to the Next.js learning hub.
Frontend Engineer Career Path
A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.
Full Stack Java Developer Career Path
A guided route through frontend foundations, Java backend engineering, delivery workflows, and interview readiness.
Sources
Sources / References
Use these Next.js references to verify the concept in official docs and continue into the most relevant SplashRide pages.
Official documentation
Related SplashRide pages
SplashRide Next.js learning path
Browse the full Next.js topic collection and learning order on SplashRide.
Next.js Interview Prep
Practice Next.js interview questions and scenario-based answers.
Frontend Engineer Career Path
A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.
Full Stack Java Developer Career Path
A guided route through frontend foundations, Java backend engineering, delivery workflows, and interview readiness.
Incremental Static Regeneration (ISR)
Master ISR — the Next.js feature that gives you static performance with dynamic freshness. Learn time-based and on-demand revalidation for real production systems.
Server-Side Rendering (SSR)
Understand Server-Side Rendering in Next.js — when to use it, how it works with the App Router, and how to avoid the performance traps that catch most developers.