Skip to main content

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:

  1. During next build
  2. Next.js runs the React code
  3. Generates HTML for the pages
  4. Stores them as static files
  5. A CDN serves them to users

How SSG differs from SSR

CriterionSSGSSR
When it rendersAt build timeOn every request
SpeedMaximumFast, but slower
Server loadNoneYes
SEOExcellentExcellent
PersonalizationNoYes

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 without cache: '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 ready
Premium

A concise answer to help you respond confidently on this topic during an interview.