Skip to main content

What is SSG in Next JS?

SSG (Static Site Generation) in Next.js is a rendering method where HTML pages are generated ahead of time, at build time, and served to users as ready-made static files.

How SSG works

  1. You run next build
  2. Next.js renders the page once
  3. The ready HTML is saved
  4. On request:
  • there is no server
  • the file is served instantly (often through a CDN)
build time → HTML → CDN → user

When SSG is used

SSG is used when:

  • data does not depend on the user
  • content rarely changes
  • speed and SEO matter

Typical cases:

  • landing pages
  • documentation
  • a blog
  • reference pages
  • public roadmaps

SSG example in the App Router

ts
// app/blog/page.tsx export const dynamic = "force-static"; export default async function Page() { const posts = await getPosts(); // runs at build time return <PostsList posts={posts} />; }

Or through fetch:

ts
await fetch("https://api.example.com/posts", { cache: "force-cache", // default → SSG });

Pros of SSG

  • maximum speed
  • excellent SEO
  • minimal server load
  • cheap hosting
  • ideal for a CDN

Cons of SSG

  • data does not update without a rebuild
  • content cannot be personalized
  • not suited for auth / user data

SSG vs SSR

SSGSSR
When it rendersbuild timerequest time
SpeedVery highHigh
SEOExcellentExcellent
FreshnessNoYes
Servernot neededneeded

SSG is not just "pure static"

In Next.js, SSG easily extends into ISR:

ts
export const revalidate = 60;

The page:

  • stays static
  • updates in the background once every 60 seconds

Short Answer

Interview ready
Premium

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