DEV Community

Jayesh Patil
Jayesh Patil

Posted on

I Deployed a React 19 SPA on Cloudflare Workers โ€” Hereโ€™s How

๐Ÿš€ Project Overview

I recently built Divines Code, a modern Single Page Application (SPA) for a digital agency.
The goal was to use the latest React ecosystem while deploying globally at the edge using Cloudflare Workers.

This post breaks down the tech stack, architecture, and deployment approach.

๐Ÿงฐ Tech Stack

React 19 (experimental)

Vite 6

TypeScript

Tailwind CSS v4

React Router DOM v7

Cloudflare Workers (Wrangler)

๐Ÿ—๏ธ Architecture

The app is a client-side rendered SPA.

Vite builds the app into a static dist/ folder

A Cloudflare Worker serves static assets

If a route isnโ€™t found, the Worker falls back to index.html

React Router handles routing on the client

This allows fast edge delivery without a traditional server.

๐Ÿงญ Routing Strategy

Uses HashRouter for compatibility with static hosting

Routes include:

/ Home

/about

/services

/work

/contact

A ScrollToTop component resets scroll on navigation

โšก Performance Optimizations

Pages are lazy-loaded using React.lazy and Suspense

Custom loading spinner improves UX

Tailwind CSS keeps styles lightweight and consistent

โ˜๏ธ Cloudflare Worker Setup

The Worker:

Serves assets from ./dist

Handles SPA fallback routing

Adds security headers:

X-Content-Type-Options

X-Frame-Options

Controls caching via Cache-Control

This keeps the app fast and secure at the edge.

๐Ÿ“ Project Structure
components/ reusable UI components
pages/ route-based pages
src/worker.ts Cloudflare Worker entry
App.tsx routing setup

๐Ÿง  Final Thoughts

This setup turned out to be:

โšก Fast

๐ŸŒ Globally distributed

๐Ÿงผ Clean to maintain

If youโ€™re experimenting with React 19 or deploying SPAs on Cloudflare Workers, Iโ€™d love to hear your experience.

Top comments (0)