Next.js supports starting as a static site or SPA, then optionally upgrading to server features later. When you runDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel/next.js/llms.txt
Use this file to discover all available pages before exploring further.
next build with output: 'export', Next.js generates an HTML file per route, enabling deployment to any static host.
Configuration
Setoutput: 'export' in next.config.js:
next build, Next.js creates an out/ folder with your HTML/CSS/JS assets.
Supported features
Server Components
Server Components run duringnext build, similar to static-site generation. The rendered HTML is output for the initial page load and a static payload for client navigation.
Client Components
Client Components are prerendered to HTML at build time. For client-side data fetching, use SWR:Route Handlers
Route Handlers render a static response duringnext build. Only GET requests are supported:
out/data.json containing { "name": "Lee" }.
Image optimization
Use a custom image loader to optimize images via a third-party service:Browser APIs
Client Components are prerendered on the server duringnext build, so browser APIs like window and localStorage are unavailable at that point. Access them only after mounting:
Unsupported features
Features requiring a Node.js server or dynamic logic at request time are not supported with static exports:- Dynamic Routes without
generateStaticParams() - Route Handlers that read from the request
- Cookies and Headers APIs
- Rewrites, Redirects, Headers config
- Middleware
- Incremental Static Regeneration
- Default image optimization loader
- Draft Mode
- Server Actions
- Intercepting Routes
Deploying
Afternext build, the out/ folder contains your static assets. Given routes / and /blog/[id], Next.js generates:
Version history
| Version | Changes |
|---|---|
v14.0.0 | next export removed in favor of output: 'export' |
v13.4.0 | App Router static export with Server Components and Route Handlers |
v13.3.0 | next export deprecated |
