Static Site Generation (SSG)
Static site generation withssr: true pre-renders routes of your application at build time. This is the default behavior when running nuxt generate.
Benefits of SSG
SEO Optimized
Fully rendered HTML pages are immediately available to search engines
Fast Loading
No server processing required, instant page loads from CDN
Cost Effective
Deploy to free or low-cost static hosting services
Scalable
CDN distribution handles any traffic volume
Generate Your Site
SSG Configuration
Configure SSG behavior in yournuxt.config.ts:
nuxt.config.ts
Fallback Pages
Nuxt generates fallback pages for static hosting:200.html (SPA Fallback)
The/200.html file serves as a single-page app fallback for dynamic routes that weren’t pre-rendered. Configure your static host to serve this file for unknown routes.
404.html (Error Page)
The/404.html file is served when a route doesn’t exist. Most static hosts serve this automatically.
You may need to configure your static hosting provider to properly serve these fallback pages. Check your provider’s documentation for SPA configuration.
Client-Side Only Rendering
If you don’t want to pre-render your routes, you can create a static single-page application (SPA) by settingssr to false:
nuxt.config.ts
.output/public/index.html entrypoint and JavaScript bundles like a classic client-side Vue.js application.
When to Use SPA Mode
Use client-side only rendering when:- Your app is behind authentication
- You’re building an admin dashboard or internal tool
- SEO is not a concern
- You need to minimize build time
Popular Static Hosting Providers
Deploy your static Nuxt site to these popular providers:- Netlify
- Vercel
- Cloudflare Pages
- GitHub Pages
Deploy to Netlify
Netlify provides zero-config deployment for Nuxt:- Connect your Git repository
- Netlify auto-detects Nuxt and configures build settings
- Build command:
npm run generate - Publish directory:
.output/public
Advanced Configuration
Custom Base URL
If your site is deployed to a subdirectory, configure the base URL:nuxt.config.ts
Asset Optimization
Optimize static assets for better performance:nuxt.config.ts
Cache Headers
Configure cache headers for different file types:nuxt.config.ts
Troubleshooting
404 errors on refresh
404 errors on refresh
Your static host needs to be configured to serve
/200.html for unknown routes. Check your provider’s SPA configuration.Missing pages after generation
Missing pages after generation
Ensure pages are discoverable:
- Link to them from other pages
- Add them to
nitro.prerender.routes - Use the
prerenderRoutes()function
API calls failing
API calls failing
Static sites cannot make server API calls. Use:
- External APIs
- Serverless functions
- Pre-fetch data during build with
useAsyncData
Environment variables not working
Environment variables not working
Client-side apps can’t access server environment variables. Use
runtimeConfig.public for client-accessible values.Next Steps
Prerendering
Learn advanced prerendering techniques
Node.js Server
Deploy with full SSR capabilities