Static sites are fast, secure, and easy to maintain, and when served from the edge, they’re nearly unbeatable in performance. In this post, I’ll walk you through the deployment process of a statically generated site (like one from Next.js, Astro, Hugo, or Eleventy) to Cloudflare Workers.
Whether you’re a fan of npm run build or hugo -D, this guide will help you serve your site directly from Cloudflare’s edge locations.
Prerequisites
Before you begin, make sure you have:
- A statically generated site (any framework like Astro, Hugo, Next.js
export, Eleventy, etc.) - Node.js installed
- A Cloudflare account
1. Generate Your Static Site
Generate your production-ready static files using your preferred framework. For example:
npm run build
This will output a directory like dist/, out/, or public/ — your final static site files.
2. Create a New Worker via Cloudflare Dashboard
- Go to the Cloudflare Workers Dashboard
- Navigate to Compute (Workers) > Create
- Select the “Workers” tab
- Select the “Start with Hello World!” option as the starter and give your Worker a name
Once created, you’ll be redirected to your Worker’s dashboard.
3. Link Your Project with Wrangler
Make sure the wrangler CLI is installed in your project:
npm install -D wrangler
From your terminal, link your local project:
npx wrangler init --from-dash <YOUR_WORKER_NAME>
This will generate a new wrangler.jsonc file which contains all the configuration for your worker.
Almost there, now, let’s make sure everything works as exepected by previewing your project locally
npx wrangler dev
This will execute a local server on port 8787, so you can access your site on http://localhost:8787
4. Deploy Your Site
Run the following to push your static site and Worker to Cloudflare:
wrangler deploy
You’ll receive a live URL like:
https://my-static-site.<your-subdomain>.workers.dev
🌐 Add a Custom Domain
To use your own domain:
- Ensure DNS is managed by Cloudflare, if not, add the Domain to Cloudflare
- In the Cloudflare dashboard, go to Compute(Workers) > Your Worker > Settings
- Under Domains & Routes click on *+ Add and enter your domain (e.g.
example.com). I will automatically add the corresponding DNS record and proxy through cloudflare network.
Final Thoughts
Deploying static sites with the new Cloudflare Workers flow is faster and more intuitive than ever. By combining edge performance with developer-friendly tooling, it’s a fantastic choice for everything from blogs to full-scale documentation sites.
If you want to skip deploying your site manually via wrangler CLI, you can connect to a repository (Github or Gitlab) and configure build and deploy commands for a CI/CD-ready static hosting.
Resources
Happy deploying!