Static Site Generation (SSG)
Static Site Generation (SSG) pre-renders all pages at build time, producing plain HTML files that can be served directly from a CDN. This approach offers the fastest possible load times since there's no server-side processing per request.
SSG is ideal for content-heavy sites like blogs, documentation, marketing pages, and portfolios. Frameworks like Astro, Next.js, Hugo, Gatsby, and Eleventy make it easy to build static sites with modern developer experiences.
Benefits include maximum performance (pre-built HTML served from CDN edge nodes), excellent SEO (complete HTML for crawlers), security (no server to attack), low cost (static hosting is nearly free), and reliability (no server to crash).
The main limitation is that content updates require a rebuild and redeploy. Incremental Static Regeneration (ISR) in Next.js and on-demand rebuilds address this by regenerating specific pages without rebuilding the entire site.
How it works
At build time the generator runs the site's templates or components against its content (Markdown files, a CMS, an API) once for every URL and writes the results out as HTML files. web.dev describes static rendering as happening at build time and producing a separate HTML file for each URL ahead of time.
Routes with parameters need their full list of URLs up front. In Astro a dynamic route exports getStaticPaths, which returns every set of parameters to build. web.dev names this as the main challenge of static rendering: every URL has to be known in advance.
The output is plain files that can be served from a CDN or object storage. The same article lists fast First Contentful Paint, low Total Blocking Time and Interaction to Next Paint, and consistently fast Time to First Byte, since nothing is computed per request.
Content changes need a rebuild. Common approaches are rebuilding automatically when the CMS publishes, regenerating only the pages that changed where the framework supports it, or rendering the few truly dynamic routes on demand. Astro prerenders every page by default and lets individual pages opt out with export const prerender = false, given a server adapter.
Example
A dynamic Astro route that is turned into one HTML file per item at build time. This is the same mechanism that builds the glossary pages on this site.
---
// src/pages/glossary/[slug].astro
import { glossaryTerms } from '../../data/glossary';
export function getStaticPaths() {
return glossaryTerms.map((t) => ({ params: { slug: t.slug }, props: { term: t } }));
}
const { term } = Astro.props;
---
<h1>{term.term}</h1>
<p>{term.definition}</p> Running the build calls getStaticPaths once, renders the template for every term, and writes files such as dist/glossary/rag/index.html. Adding a term to the data file adds a page on the next build; nothing runs on a server when a visitor requests it.
Common confusion
What is the difference between static site generation and server-side rendering?
Both deliver complete HTML. Static generation renders every page once at build time, so pages are files and can be cached anywhere, but they only change when the site is rebuilt. Server-side rendering renders on each request, so pages can use request data such as cookies and are always current, at the cost of server work per request.
Does a static site mean the pages cannot be interactive?
No. "Static" describes when the HTML is produced, not what the page can do. Statically generated pages can include JavaScript, call APIs from the browser and hydrate interactive components. They simply do not need a server to produce the HTML.
Related tools & demos
- Server-Side Rendering (SSR) The per-request alternative.
- Hydration How interactive parts of a static page come to life.
Further reading
- Rendering on the Web (Addy Osmani, Jason Miller) web.dev
- On-demand rendering Astro documentation
Want to learn more?
Explore more developer terms or read in-depth articles on the blog.
Browse all terms