# Static Site Generation \(SSG\)

Static site generation renders routes into deployable HTML files before requests arrive, usually during a build or publishing process.

- Type: method
- Domain: Engineering & architecture
- Level: Intermediate
- Last reviewed: 2026-09-23
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/static-site-generation/>)

## What it means

Static site generation \(SSG\), also called build-time rendering or prerendering in some systems, produces HTML and related assets ahead of user requests. A server or content delivery network can serve the resulting files without executing view logic for each visit. Static generation describes delivery timing, not whether pages contain JavaScript or later fetch dynamic data.

## Why it matters

Prebuilt output can be fast, cacheable, inexpensive to serve, and operationally simple. The tradeoff shifts work and freshness concerns into build, invalidation, and deployment workflows.

## When to use it

Use SSG for documentation, marketing, editorial, catalogue, and other routes whose content can tolerate publishing latency. Use request-time or client rendering for highly personalized, permission-sensitive, or continuously changing views.

## How it works

1. A build process discovers the routes that should exist.
2. It reads content and data available at build time.
3. Templates or components render each route to HTML and assets.
4. The generated output is deployed to a static host or CDN.
5. Content changes trigger rebuilds, selective regeneration, or cache invalidation.

## A practical example

A product documentation site generates thousands of versioned pages when approved content changes. A CDN serves the HTML globally, while a small client script adds search; urgent corrections trigger a targeted rebuild.

## Where it breaks

Large route sets can make builds slow, deployed content can become stale, and build-time access to sensitive data can leak it into public files. Personalized pages and unpredictable route combinations do not fit straightforward generation.

## Common mistakes

- Calling a generated page noninteractive merely because its HTML is prebuilt.
- Embedding secrets or private records in public build output.
- Rebuilding every route for a small content change without measuring the cost.
- Ignoring freshness, rollback, and invalidation requirements.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/static-site-generation/#visualization-static-site-generation>)

## Sources

1. [Rendering on the Web](<https://web.dev/articles/rendering-on-the-web>) — web.dev · Official technical guidance
2. [Pre-rendering](<https://nextjs.org/learn/pages-router/data-fetching-pre-rendering>) — Next.js · Official framework documentation

## Related topics

- [Server-Side Rendering \(SSR\)](<https://wiki.soroush.uk/topic/server-side-rendering/>)
- [Multi-Page Application \(MPA\)](<https://wiki.soroush.uk/topic/multi-page-application/>)
- [Cache](<https://wiki.soroush.uk/topic/cache/>)
