What is SSG and when is it used?
SSG (Static Site Generation) is an approach where pages are generated ahead of time at build time and served to the user as ready-made HTML files.
In short:
build -> ready HTML -> instant load
How SSG works
Using Next.js as an example:
- During
next build - Next.js runs the React code
- Generates HTML for the pages
- Stores them as static files
- A CDN serves them to users
How SSG differs from SSR
| Criterion | SSG | SSR |
|---|---|---|
| When it renders | At build time | On every request |
| Speed | Maximum | Fast, but slower |
| Server load | None | Yes |
| SEO | Excellent | Excellent |
| Personalization | No | Yes |
Why SSG is needed
1. Maximum speed
- HTML is already ready
- served from a CDN
- minimal TTFB
2. Minimal infrastructure
- no server needed
- no computation per request
- cheap hosting
3. Great for SEO
- all content is available immediately
- indexes reliably
When to use SSG
- landing pages
- blogs
- documentation
- marketing pages
- reference pages
- "About us" pages
Content rarely changes and is the same for everyone.
When SSG does NOT fit
- personalized data
- data depends on cookies / auth
- frequent content changes (without ISR)
SSG in Next.js
SSG is enabled automatically when:
- the page does not use dynamic data
fetch()is used withoutcache: 'no-store'- there is no dependency on the request
It is also often used together with ISR (updates without a rebuild).
Short interview answer
SSG is generating HTML pages at build time. It is used for fast, SEO-friendly content that rarely changes and is the same for all users.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.