Static Site Generation (SSG): Pre-rendered at Build Time
What you'll learn: How SSG creates HTML once during the build process and serves identical static files to all users from a CDN.
The Core Idea
Static Site Generation is a rendering strategy where you generate all your HTML pages once, at build time, before any user requests them. Think of it like printing a book: you write it once, print thousands of copies, and distribute them to bookstores. Every reader gets the exact same book—no custom printing per person.
With SSG, your build process runs your React components, fetches any necessary data, and outputs plain HTML files. These files are then deployed to a CDN (Content Delivery Network) and served instantly to users. No server executes React code on each request—the work is done ahead of time.
How It Works
During your npm run build:
- React renders every page/route
- Data is fetched (from APIs, databases, markdown files)
- HTML is generated and written to disk
- Static files are deployed to a CDN
When users visit your site:
- They receive pre-built HTML instantly from the nearest CDN edge
- No server processing happens
- No data fetching happens per-request
- Every user sees the same HTML (until you rebuild)
The Trade-off
SSG is blazingly fast because you're serving cached static files. But the content is frozen at build time—if your data changes, you must rebuild and redeploy to update the site. Perfect for blogs, documentation, and marketing pages. Problematic for user-specific dashboards or real-time data.
Key Takeaway: SSG pre-renders your entire site during build, creating static HTML files served from CDNs for maximum speed, but content cannot change between builds without redeploying.