Skip to main content
The SSG (Static Site Generation) helper allows you to pre-render your Hono application routes into static HTML files, enabling deployment to static hosting services.

Import

Basic Usage

Generate Static Files

The toSSG function pre-renders your app routes:
This creates:

File System Module

Provide a file system module for writing files:

Node.js

Deno

Bun

Options

Output Directory

string
default:"./static"
Output directory for generated files

Concurrency

Control how many routes are processed in parallel:
number
default:"2"
Number of routes to process concurrently

Extension Mapping

Customize file extensions based on content type:

Dynamic Routes

For routes with parameters, use ssgParams middleware to define which parameter values to generate:

Basic Dynamic Routes

Generates:

Dynamic Parameters from Function

Multiple Parameters

Controlling SSG Behavior

Disable SSG for Specific Routes

Prevent certain routes from being statically generated:

Only Generate During SSG

Make routes available only during static generation:

Check if in SSG Context

Hooks

Customize the generation process with hooks:

Before Request Hook

Modify requests before processing:
Return false to skip a route:

After Response Hook

Modify responses before writing files:
Return false to skip writing the file:

After Generate Hook

Run logic after all files are generated:

Plugins

Plugins bundle hooks together:

Built-in Plugins

function
Default plugin with standard behavior
function
Handles redirect responses during generation

Result Object

The toSSG function returns a result object:

Success Case

Error Case

Build Script Example

Create a build script for your project:
Add to package.json:

Deployment

Deploy generated files to static hosting:

Vercel

Deploy the dist folder as a static site

Netlify

Configure build command and publish directory

Cloudflare Pages

Push to Git and configure Pages project

GitHub Pages

Deploy from repository with GitHub Actions

Best Practices

Use ssgParams for all dynamic routes, otherwise they will be skipped during generation.
Routes that depend on request headers or real-time data may not work correctly when statically generated.
Use isSSGContext to provide different behavior during static generation vs. runtime.

Advanced: Adaptor Interface

Create runtime-specific adaptors: