Output Modes
Astro supports three output modes, configured in yourastro.config.mjs file:
Static Mode
Default behavior. All pages are pre-rendered at build time into static HTML files.Static mode is ideal for content-heavy sites where pages don’t change frequently, providing the best performance and lowest hosting costs.
src/pages/index.astro
Server Mode
All pages rendered on-demand. Pages are rendered on the server for each request, allowing for dynamic content and server-side logic.src/pages/api/user.astro
Hybrid Mode
Mix static and server rendering. Pages are pre-rendered by default, but you can opt-in to on-demand rendering for specific pages.src/pages/product/[id].astro
Page-Level Control
You can control rendering per-page using theprerender export:
- Server Mode
- Hybrid Mode
In
output: 'server' mode, pages are server-rendered by default. Use export const prerender = true to pre-render specific pages:src/pages/about.astro
Adapters
To use SSR, you need an adapter for your deployment platform. Adapters allow Astro’s server output to work with your hosting provider’s runtime.Official Adapters
Node.js
Deploy to any Node.js server
Vercel
Deploy to Vercel’s edge network
Netlify
Deploy to Netlify functions
Cloudflare
Deploy to Cloudflare Workers
Installing an Adapter
Configure output mode
The adapter will automatically configure your
astro.config.mjs:astro.config.mjs
Build Process
During the build process, Astro analyzes your routes and determines how each should be rendered based on your configuration:Static Build
Static Build
- All pages are rendered to HTML at build time
- Assets are optimized and bundled
- Output is a directory of static files ready to serve
- Located in
dist/by default
Server Build
Server Build
- Creates a server entry point for on-demand rendering
- Pre-renders pages marked with
prerender: true - Bundles server-side code and dependencies
- Outputs both static assets and server chunks
When to Use Each Mode
Static
Best for:
- Blogs and documentation
- Marketing sites
- Content-heavy sites
- Maximum performance
Server
Best for:
- User dashboards
- Personalized content
- Real-time data
- Authentication required
Hybrid
Best for:
- E-commerce sites
- SaaS applications
- Mixed content types
- Optimal flexibility
Performance Considerations
Static Generation Benefits
- Fastest possible load times - No server computation required
- Easy to cache - CDN-friendly static files
- Lower hosting costs - Simple file hosting
- Better SEO - Instant content availability
Server Rendering Benefits
- Fresh data - Always up-to-date content
- Personalization - User-specific pages
- Security - Hide sensitive logic
- Dynamic behavior - Respond to request data
Related Resources
Adapters
Learn about deployment adapters
Server Islands
Mix static and dynamic content
Middleware
Add server-side logic
Actions
Handle form submissions