Deploying Static Frontends & SPAs
Complete guide to deploying static HTML/CSS/JS and Vite/React SPAs to Cloudflare Pages, Netlify, and AWS S3 + CloudFront with SPA rewrite rules.
Static frontends (plain HTML/CSS/JS, Vite + React, Vue, Svelte) compile to pure static files (index.html, .js, .css, images) and are best deployed to globally distributed Content Delivery Networks (CDNs).
1. Cloudflare Pages (Free, Unlimited Bandwidth)
- Go to Cloudflare Dashboard $\rightarrow$ Workers & Pages $\rightarrow$ Create Application $\rightarrow$ Pages.
- Connect your Git repository.
- Configure build settings:
- Framework Preset:
Vite(orCreate React App) - Build Command:
pnpm build - Build Output Directory:
dist(orbuild)
- Framework Preset:
- Click Save and Deploy.
2. SPA Client-Side Routing Fallback Rules
Single Page Applications (SPAs) manage routing in the browser. When a user navigates directly to https://example.com/dashboard, the web server must return index.html instead of a 404 error.
Netlify (_redirects file in ./public/):
/* /index.html 200Cloudflare Pages (_routes.json or 404.html):
For standard SPAs, symlink index.html to 404.html or configure SPA mode in dashboard.
Nginx (Self-Hosted):
location / {
root /var/www/my-spa/dist;
try_files $uri $uri/ /index.html;
}3. AWS S3 + CloudFront CDN Architecture
Client Browser ──► AWS CloudFront (Global CDN Cache + SSL) ──► S3 Bucket (Private Static Origin)- Create a private S3 bucket and upload your
./distbuild files. - Create a CloudFront Distribution pointing to the S3 bucket via Origin Access Control (OAC).
- Configure Custom Error Response: Map HTTP Error
403and404to/index.htmlwith HTTP response code200.
Related Guides
Deploy Next.js to Vercel
Complete step-by-step guide to deploying Next.js App Router applications to Vercel with automatic CI/CD, preview deployments, and environment variables.
Deploying a Node.js App to a Linux VPS
Complete end-to-end production guide for deploying a Node.js Express/TypeScript backend to an Ubuntu VPS using systemd, Nginx reverse proxy, and Let's Encrypt SSL.