SSG
Static Site Generation
Generates HTML at build time. Fast loading. Gatsby, Hugo, Astro.
Static Site Generation
Generates HTML at build time. Fast loading. Gatsby, Hugo, Astro.
SSG (Static Site Generation) is a rendering method that pre-generates the HTML of all pages at build time. Because already completed HTML files are served directly from a server or CDN, no server computation is needed, providing very fast loading speeds.
Next.js's getStaticProps, Gatsby's GraphQL queries, and Astro's static generation are representative SSG implementation methods. Because data is fetched at build time and included in the HTML, data received from a CMS or API can be converted into static pages.
SSG is ideal for sites whose content does not change often, such as blogs, documentation sites, and marketing pages. When cached on a CDN, it guarantees fast response times anywhere in the world, and there is almost no server load.
With ISR (Incremental Static Regeneration), you can regenerate pages periodically while retaining the advantages of SSG. The revalidate option updates the page in the background at set intervals to reflect the latest data.
// Next.js SSG with getStaticProps
// pages/blog/[slug].tsx
interface Post {
slug: string;
title: string;
content: string;
publishedAt: string;
}
// λΉλ νμμ λͺ¨λ κ²½λ‘ μμ±
export async function getStaticPaths() {
const posts = await fetch('https://api.example.com/posts')
.then(res => res.json());
return {
paths: posts.map((post: Post) => ({
params: { slug: post.slug }
})),
fallback: 'blocking' // μ κ²½λ‘λ SSR ν μΊμ
};
}
// λΉλ νμμ λ°μ΄ν° νμΉ
export async function getStaticProps({ params }: { params: { slug: string } }) {
const post = await fetch(`https://api.example.com/posts/${params.slug}`)
.then(res => res.json());
if (!post) {
return { notFound: true };
}
return {
props: { post },
revalidate: 3600 // ISR: 1μκ°λ§λ€ μ¬μμ±
};
}
export default function BlogPost({ post }: { post: Post }) {
return (
<article>
<h1>{post.title}</h1>
<time>{post.publishedAt}</time>
<div dangerouslySetInnerHTML={{ __html: post.content }} />
</article>
);
}
// Astro SSG μμ
// src/pages/blog/[slug].astro
---
export async function getStaticPaths() {
const posts = await fetch('https://api.example.com/posts').then(r => r.json());
return posts.map(post => ({
params: { slug: post.slug },
props: { post }
}));
}
const { post } = Astro.props;
---
<article>
<h1>{post.title}</h1>
<Fragment set:html={post.content} />
</article>
In a technical meeting:
"SSG is the right choice for a documentation site. If you deploy on Vercel, it's served straight from the CDN, so response times should come in under 50ms. If you regenerate with ISR every hour, content updates are automatic too."
In a technical interview:
"What's the difference between SSG and SSR?" - "SSG generates HTML at build time, and SSR generates it at request time. SSG is faster, but if you need real-time data, you have to use SSR or ISR."
In a code review:
"This page is using getServerSideProps, but the data only changes once an hour. If we switch to getStaticProps + revalidate, the server load drops significantly."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free