Deployment Modes
TanStack Start supports multiple deployment modes:Server-Side Rendering (SSR)
Full-stack applications with server rendering, streaming, and server functions:- Node.js servers - Express, Fastify, or standalone
- Serverless platforms - Vercel, Netlify, AWS Lambda
- Edge runtime - Cloudflare Workers, Deno Deploy
- Containerized - Docker on any cloud platform
Static Site Generation (SSG)
Pre-render pages at build time for static hosting:- Great for content-heavy sites
- Deploy to CDNs for global distribution
- No server runtime required
Single Page Application (SPA)
Client-side only applications:- Traditional SPA deployment
- Any static file hosting
- Requires client-side routing configuration
Platform-Specific Deployment
Cloudflare Pages
Deploy SSR applications to Cloudflare’s edge network: Configuration:wrangler.toml
Vercel
Deploy to Vercel’s serverless platform: Vercel automatically detects TanStack Start projects and configures them correctly.Netlify
Deploy to Netlify with edge functions:Node.js Server
Deploy to any Node.js environment: Custom server:server.mjs
Docker
Containerize your application:Dockerfile
Static Hosting (SPA Mode)
Deploy as a static site:Configure redirects
For client-side routing, redirect all requests to Vercel (Nginx:
index.html:Netlify (public/_redirects):vercel.json):Environment Variables
Manage environment-specific configuration:Build-Time Variables
Vite exposes variables prefixed withVITE_:
.env
Runtime Variables (Server-Side)
Access variables in server functions and loaders:Platform-Specific Configuration
Vercel:Asset Management
TanStack Start automatically handles asset optimization:Asset Manifest
The build generates a manifest of all assets:.output/manifest.json
CDN Integration
Transform asset URLs to use a CDN:app/server.ts
Static Assets
Place static assets in thepublic/ directory:
Performance Optimization
Code Splitting
TanStack Router automatically code-splits by route:Compression
Enable compression in your server:Caching Strategies
Set appropriate cache headers:- Static assets:
public, max-age=31536000, immutable - API responses:
public, max-age=60, stale-while-revalidate=300 - HTML pages:
public, max-age=0, must-revalidate
Preloading
Preload critical resources:Monitoring and Observability
Error Tracking
Integrate error tracking:app/start.ts
Performance Monitoring
Track Core Web Vitals:Logging
Implement structured logging:Best Practices
Use environment variables for configuration
Use environment variables for configuration
Never hardcode secrets or environment-specific values:
Enable compression
Enable compression
Reduce transfer size with gzip or brotli compression:
Set up proper caching
Set up proper caching
Use appropriate cache headers for different content types:
Monitor application health
Monitor application health
Set up health check endpoints:
Test production builds locally
Test production builds locally
Always test production builds before deploying:
Use CDN for static assets
Use CDN for static assets
Serve assets from a CDN for global distribution:
Troubleshooting
Build Failures
Issue: Build fails with module errors Solution: Check that all dependencies are installed and versions are compatible:Runtime Errors
Issue: Application crashes on startup Solution: Check environment variables are set correctly:Performance Issues
Issue: Slow page loads Solution:- Enable streaming:
defaultStreamHandler - Add Suspense boundaries for slow components
- Implement proper caching strategies
- Use CDN for static assets
Related Resources
Server Rendering
Learn how SSR works
Streaming
Optimize with streaming
Deployment Guide
Complete deployment guide
Static Generation
Pre-render pages at build time