Skip to main content
TanStack Start applications can be deployed to various hosting platforms. The deployment process varies based on whether you’re building a traditional Single Page Application (SPA) or using server-side rendering (SSR).

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:
1

Install adapter

2

Configure the adapter

app/server.ts
3

Deploy

Configuration:
wrangler.toml

Vercel

Deploy to Vercel’s serverless platform:
1

Install Vercel CLI

2

Configure build

vercel.json
3

Deploy

Vercel automatically detects TanStack Start projects and configures them correctly.

Netlify

Deploy to Netlify with edge functions:
1

Create configuration

netlify.toml
2

Deploy

Node.js Server

Deploy to any Node.js environment:
1

Build the application

2

Start the server

Custom server:
server.mjs

Docker

Containerize your application:
Dockerfile
Build and run:

Static Hosting (SPA Mode)

Deploy as a static site:
1

Build for static hosting

2

Configure redirects

For client-side routing, redirect all requests to index.html:Netlify (public/_redirects):
Vercel (vercel.json):
Nginx:
3

Deploy static files

Upload the .output/public directory to your static hosting provider.

Environment Variables

Manage environment-specific configuration:

Build-Time Variables

Vite exposes variables prefixed with VITE_:
.env

Runtime Variables (Server-Side)

Access variables in server functions and loaders:
Security: Server-side environment variables are never exposed to the client.

Platform-Specific Configuration

Vercel:
Netlify:
Cloudflare:

Asset Management

TanStack Start automatically handles asset optimization:

Asset Manifest

The build generates a manifest of all assets:
.output/manifest.json
The server uses this manifest to inject correct asset URLs.

CDN Integration

Transform asset URLs to use a CDN:
app/server.ts
Dynamic CDN selection:

Static Assets

Place static assets in the public/ directory:
Reference them with absolute paths:

Performance Optimization

Code Splitting

TanStack Router automatically code-splits by route:

Compression

Enable compression in your server:

Caching Strategies

Set appropriate cache headers:
Cache strategies:
  • 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

Never hardcode secrets or environment-specific values:
Reduce transfer size with gzip or brotli compression:
Use appropriate cache headers for different content types:
Set up health check endpoints:
Always test production builds before deploying:
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:
  1. Enable streaming: defaultStreamHandler
  2. Add Suspense boundaries for slow components
  3. Implement proper caching strategies
  4. Use CDN for static assets

Server Rendering

Learn how SSR works

Streaming

Optimize with streaming

Deployment Guide

Complete deployment guide

Static Generation

Pre-render pages at build time