Static Generation
TanStack Start supports static site generation (SSG), enabling you to prerender pages at build time. This results in optimal performance, SEO, and deployment flexibility.What is Static Generation?
Static generation prerenders routes at build time, producing HTML files that can be served from any static host. Benefits include:- Optimal Performance: No server-side rendering overhead
- Better SEO: Fully rendered HTML for search engines
- Lower Costs: Deploy to free static hosting
- Global Distribution: Easy CDN deployment
- Offline Support: Progressive web app capabilities
Configuring Static Generation
Build Static Site
Run the build command:dist/client for each specified route.Dynamic Route Prerendering
Prerender routes with dynamic parameters:Incremental Static Regeneration
Combine static generation with on-demand regeneration:On-Demand Revalidation
Trigger static page regeneration:Time-Based Revalidation
Schedule periodic rebuilds:Hybrid Static and Dynamic
Combine static pages with dynamic routes:/blog/[slug]) fall back to SSR or client-side rendering.
Client-Side Data Fetching
Load additional data on the client:Sitemap Generation
Generate sitemaps during build:RSS Feed Generation
Generate RSS feeds for static content:Image Optimization
Optimize images during build:Metadata Generation
Generate SEO metadata for static pages:Progressive Web App
Generate PWA manifest and service worker:Build-Time Environment Variables
Access environment variables during build:Best Practices
- Prerender high-traffic pages: Focus on pages that benefit most from SSG
- Use incremental builds: Only rebuild changed pages
- Optimize images: Compress and convert to modern formats
- Generate sitemaps: Help search engines discover your content
- Implement caching: Set aggressive cache headers for static assets
- Monitor build times: Keep builds fast for better developer experience
- Test static output: Verify generated HTML is correct
- Use CDNs: Distribute static files globally
- Implement fallbacks: Handle non-prerendered routes gracefully
- Version assets: Use content hashing for cache busting