Static Site Generation (SSG)
Pre-rendering pages to static HTML at build time. The fastest possible page loads because there's no server-side computation on each request.
What is Static Site Generation (SSG)?
In short
Static Site Generation (SSG) is a technique where every page is rendered to plain HTML files ahead of time, during a build step, instead of being generated on each request. Those finished HTML, CSS, and JavaScript files are served directly from a CDN, so there is no database query or server-side rendering work when a visitor loads the page, which makes loads close to instant.
What SSG actually is
With SSG, the work of building a page happens once, when you deploy, not every time someone visits. A build process runs your templates and data through a generator, and the output is a folder of static files: one HTML file per route, plus the CSS, JavaScript, and images they need.
Compare this to the two alternatives. Server-side rendering (SSR) builds the HTML on the server for every single request, so it can show the latest data but adds compute and latency to each visit. Client-side rendering (CSR) ships an empty HTML shell and a JavaScript bundle that fetches data and draws the page in the browser, which delays the first meaningful paint. SSG sidesteps both by having the finished page ready before anyone asks for it.
The catch is that the content is frozen at build time. If your data changes, you have to rebuild and redeploy, or use a hybrid approach that re-renders specific pages on a schedule or on demand.
How it works under the hood
A static site generator runs in three steps. First it loads your content, which can be Markdown files, MDX, JSON, or data pulled from a headless CMS or an API. Second it passes that content through page templates or React components to produce HTML strings. Third it writes those strings to disk as .html files, alongside a manifest of assets.
Frameworks like Next.js and Astro let you control which pages get generated. In Next.js you export a function such as generateStaticParams that returns the list of dynamic routes, for example every blog slug or every product id, and the build loops over that list and emits one HTML file per entry. A site with 754 pages produces 754 HTML files in a single build.
Because the output is just files, deployment is trivial. You upload the folder to a CDN such as Cloudflare, Vercel's edge network, or Amazon CloudFront backed by S3. The CDN caches every file at edge locations near users, so a request in Tokyo is served from a Tokyo node without ever reaching your origin. Time to first byte typically lands under 100ms because there is nothing to compute.
When to use it and the trade-offs
SSG is the right call for content that changes rarely and is the same for every visitor: marketing pages, documentation, blogs, course material, and product catalogs. These benefit most from the speed, the low cost, and the strong SEO that comes from shipping complete HTML that crawlers can read without running JavaScript.
It is a poor fit for highly personalized or real-time content. A user dashboard, a stock ticker, or a shopping cart that differs per session cannot be baked in at build time. For those you reach for SSR or CSR, or you statically generate the shell and hydrate the dynamic parts on the client.
The main trade-off is build time and staleness. A site with tens of thousands of pages can take many minutes to build, and any content edit means a rebuild. Modern frameworks soften this with Incremental Static Regeneration, where a page is generated on the first request after its cache window expires and then served statically again, so you get fresh content without rebuilding the whole site.
A concrete example
Consider a documentation site with 500 articles written in Markdown. At build time the generator reads all 500 files, renders each through a shared layout, and writes 500 HTML files plus a search index. The whole build might take 90 seconds and run once per content update in CI.
When a reader opens an article, the CDN returns the prebuilt HTML in tens of milliseconds. There is no database, no server process, and no cold start. The same setup serves ten readers or ten million readers at nearly the same cost, because the CDN absorbs the traffic and the origin is barely touched.
This is exactly why developer docs, learning platforms, and JAMstack sites lean on SSG. You trade a little build complexity and the need to redeploy on changes for pages that are fast, cheap to host, resilient to traffic spikes, and easy for search engines to index.
Where it is used in production
Vercel and Next.js
Next.js popularized SSG with generateStaticParams and Incremental Static Regeneration, and Vercel serves the output from its global edge network.
Cloudflare Pages
Hosts statically generated sites and serves the prebuilt files from 300+ edge locations for sub-100ms time to first byte.
Amazon S3 plus CloudFront
A classic pairing where built HTML lives in an S3 bucket and CloudFront caches and distributes it globally with no servers to run.
GitHub Pages
Serves Jekyll-generated static sites for free, which is how a large share of open-source project documentation is published.
Frequently asked questions
- What is the difference between SSG and SSR?
- SSG renders pages to HTML once at build time and serves the same files to everyone, so there is no per-request compute. SSR renders the HTML fresh on the server for each request, which lets it show up-to-date or personalized data but adds latency and server cost to every visit.
- Can a static site show dynamic or personalized content?
- Yes, but the dynamic parts run in the browser. You generate the static shell at build time, then client-side JavaScript fetches user-specific data after the page loads. Truly per-user pages are better suited to SSR or hybrid rendering.
- How do you update content on a static site?
- You change the source content and trigger a rebuild and redeploy, usually automated through CI. To avoid rebuilding everything, frameworks offer Incremental Static Regeneration or on-demand revalidation, which rebuild only the pages that changed.
- Why is SSG good for SEO?
- Search crawlers receive complete HTML immediately, with all the text and metadata present, so they do not have to execute JavaScript to see the content. Combined with fast load times, this tends to improve indexing and ranking.
- Is SSG slow for sites with many pages?
- Build time grows with page count, so a site with tens of thousands of pages can take several minutes to build. Incremental Static Regeneration helps by generating pages on first request after expiry instead of regenerating the entire site every time.
Learn Static Site Generation (SSG) hands-on
This page explains the idea. The full lesson lets you step through the ring as servers join and leave, read the implementation, and check yourself with a quiz. It is one of 760+ lessons in the System Design Masterclass, from your first API call to distributed consensus. Eleven Foundation lessons are free, no signup. Lifetime access is ₹499 in India or $7.99 worldwide, one payment, no subscription.
Related lessons
Lessons that touch on Static Site Generation (SSG) as part of a larger topic.
See also
Related glossary terms you might want to look up next.
ISR
Incremental Static Regeneration: a Next.js feature that re-generates static pages in the background after a specified time interval, combining SSG speed with fresh data.
SSR
Server-Side Rendering: generating HTML on the server for each request. Slower than SSG but always returns fresh data. Good for personalized or frequently changing pages.
CDN
A network of servers distributed globally that caches content close to users. Netflix uses CDNs to stream video from servers near you, not from one central location.
Content Delivery
The process of distributing and serving content to users from locations geographically close to them for faster load times.
Edge Computing
Running computation at the network edge, close to the user, instead of in a central data center. Reduces latency for real-time applications like IoT and streaming.
HTTP Caching
Browser and proxy caching controlled by HTTP headers like Cache-Control, ETag, and Last-Modified. Eliminates redundant network requests for unchanged resources.