Static Generation
Static Site Generation
Pre-render pages at build time for better performance.
What Is SSG?
SSG (Static Site Generation) renders pages to static HTML during the build process (dex build / dexPrerender). The generated HTML is served directly without server-side runtime rendering.
Configuration & Usage
Set rendering strategy globally in dex.config.ts:
// dex.config.ts
export default {
renderStrategy: 'ssg',
}Or configure per-page via page metadata export:
// web/pages/blog/[slug].tsx
export const metadata = {
renderStrategy: 'ssg',
title: 'Blog Post',
description: 'A pre-rendered blog post',
ogImage: 'https://example.com/og.png',
}
export default function BlogPost() {
return <article>Pre-rendered content</article>
}How Prerendering Works
- During
dex build,dexPrerenderevaluates routes whererenderStrategy === 'ssg'. - Each page is rendered wrapped in
<RouterContext.Provider>with static route state. <head>metadata (metadata) and Google Fonts (fonts) are injected.- Output HTML files are written to
build/__ssg/and copied tobuild/<route>/index.html. dexSpaFallbackautomatically detects and serves pre-rendered SSG HTML files at runtime.
See Also
- Recipes Index — Other recipes
- Production Build — Build process