What is static generation?
ReactThe short answer
Static generation (SSG) means generating HTML pages at build time, not at request time. The pages are created once during the build process and served as static files. This is the fastest rendering strategy because the server just sends a pre-built file — no computation per request.
How it works
- You run
next build(or your framework's build command) - The framework runs your components and generates HTML files
- The HTML files are stored and served directly by a CDN
- Every user gets the exact same pre-built page
// Next.js — this page is statically generated at build timeasync function BlogPost({ params }) { const post = await getPostFromDatabase(params.slug); return ( <article> <h1>{post.title}</h1> <p>{post.content}</p> </article> );}The database is queried once during the build. After that, the HTML is served to every user without hitting the database again.
SSG vs SSR vs CSR
| When HTML is generated | Speed | Data freshness | |
|---|---|---|---|
| SSG | Build time | Fastest | Stale until rebuild |
| SSR | Request time | Fast (but server work per request) | Always fresh |
| CSR | Client (browser) | Slowest initial load | Always fresh |
When to use static generation
Good for:
- Blog posts and documentation
- Marketing pages and landing pages
- Product listing pages that do not change often
- Any page where the content is the same for all users
Not good for:
- User-specific content (dashboards, profiles)
- Pages that need real-time data
- Content that changes every few minutes
Incremental Static Regeneration (ISR)
ISR is a middle ground between SSG and SSR. Pages are statically generated but can be refreshed in the background after a set time:
// Next.js — revalidate every 60 secondsexport const revalidate = 60;async function ProductPage({ params }) { const product = await getProduct(params.id); return <h1>{product.name}</h1>;}The first user gets the cached page. After 60 seconds, the next request triggers a background rebuild. The stale page is served while the new one is being generated.
Interview Tip
Explain the difference between SSG and SSR clearly — SSG generates pages at build time, SSR generates them per request. Mention ISR as the modern improvement that combines the speed of SSG with fresher data. Knowing when to use each shows you can make architecture decisions.
Why interviewers ask this
This question tests if you understand the different rendering strategies and their tradeoffs. Interviewers want to see if you can choose the right strategy for a given use case — a blog should be statically generated, a dashboard should use SSR or CSR. Making the right choice here directly affects performance and cost.