Publishing a Static Site on Cloudflare
On this page19 items
On the previous page, we built a Worker that runs code on every request. This time we’ll publish a site that serves files as they are.
This covers a wide range: from simple sites that are just HTML, CSS and images, to sites generated by static site generators such as Astro, Next.js, Hugo and Jekyll, to single-page applications built with React or Vue. Portfolios, tech blogs, corporate landing pages, documentation sites: a large share of the websites out there can be published this way.
And the important point is that requests for static files are free and unlimited. For a personal site, the cost really does come to zero.
What you’ll learn on this page#
- The two ways to publish a static site on Cloudflare, and which to choose
- How to publish with a single command
- How to connect GitHub so that a push is all it takes to update
- Assigning a custom domain, and configuring routing for SPAs
- The scope of the free tier, and limits you should know about
Workers or Pages?#
There are two ways to publish a static site on Cloudflare. As mentioned in Cloudflare Pages in Chapter 5, the two are currently in the middle of being merged.
- Cloudflare Pages: A service built specifically for static site hosting. It’s still fully in service
- Workers static assets: Workers with the added ability to serve files. This is the recommended option for new projects
Pages isn’t being discontinued. But new features are being added on the Workers side, so if you’re building something now, Workers is the natural choice.
Here’s a rule of thumb for when you’re unsure.
| Workers (static assets) | Pages | |
|---|---|---|
| New projects | Recommended | Still available |
| Serving static files | Free, unlimited | Free, unlimited |
| Adding dynamic processing | Write it directly in the same project | Write it in Functions |
| Cron, Durable Objects, etc. | Available | Partly unavailable |
| Domains not managed by Cloudflare | Not possible | Possible via CNAME |
This page covers the Workers approach.
Method 1: Publish with a command#
This is the fastest way. You can publish a folder that already has an index.html as-is.
Create a minimal setup#
Make a working folder and put the following two files in it.
First, public/index.html.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My first static site</title>
</head>
<body>
<h1>Published on Cloudflare</h1>
</body>
</html>Next, wrangler.jsonc directly under the folder.
{
"name": "my-static-site",
"compatibility_date": "2026-08-20",
"assets": {
"directory": "./public"
}
}That’s it. You don’t need a single line of JavaScript. You don’t even need to specify main.
Deploy#
npx wrangler deployWithin seconds, https://my-static-site.your-subdomain.workers.dev is live. Go ahead and open it.
To check it locally, use the same command as on the previous page.
npx wrangler dev
If you use a static site generator#
If you build with Astro, Hugo, Next.js or similar, just point directory at the build output folder.
"assets": {
"directory": "./dist"
}The output folder varies by tool: dist, out, build, _site and so on. Specify the folder name that appears when you build locally.
There are also dedicated templates for these frameworks.
npm create cloudflare@latest -- my-site --framework=astroWith this, the project is created with that framework’s configuration already included.
Method 2: Auto-deploy with GitHub#
In real-world use, this is the more convenient option. Just push to GitHub, and the build and deploy happen automatically.
In the Cloudflare dashboard, choose Workers & Pages → Create application → Import a repository, and connect a GitHub or GitLab repository.
There are three main settings.
| Setting | Example | Description |
|---|---|---|
| Build command | npm run build | Leave blank if no build is needed |
| Output directory | dist | Where the generated files go |
| Production branch | main | Pushes here update production |
Once connected, it works like this.
- Push to
main→ it builds automatically and production is updated - Open a pull request → a dedicated preview URL is created, so you can actually open and check the changes
- The build status shows up on GitHub → a comment is added to the pull request
This preview feature is especially handy. “Checking a fix at a real URL before it goes to production” works with no extra setup.
Note that self-hosted GitHub and GitLab are not supported (as of August 2026).
Assigning a custom domain#
It works fine on workers.dev, but a real site uses a custom domain.
Writing it in the config file works the same way as on the previous page.
{
"name": "my-static-site",
"compatibility_date": "2026-08-20",
"assets": { "directory": "./public" },
"routes": [
{ "pattern": "www.example.com", "custom_domain": true }
]
}When you deploy, the DNS record and certificate are set up automatically.
You can also set it up from the dashboard. On the Worker’s details screen, go to Settings → Domains & Routes → Add and enter the hostname you want to use.
404 pages and SPAs#
A question that always comes up with static sites is “what happens when someone visits a URL that doesn’t exist?” You specify this with not_found_handling in the config file.
Ordinary sites (blogs, corporate sites, etc.)#
"assets": {
"directory": "./dist",
"not_found_handling": "404-page"
}If you provide a 404.html, it’s shown for URLs that don’t exist.
SPAs (apps built with React, Vue, etc.)#
"assets": {
"directory": "./dist",
"not_found_handling": "single-page-application"
}Without this setting, an SPA shows the symptom “the top page loads, but opening a URL directly gives a 404.” In an SPA, routing is handled by JavaScript in the browser, so the server needs to return index.html for every URL. This setting makes it behave that way.
When you want to add dynamic processing#
After publishing a static site, requests like “I want a contact form” or “I want to count visits” come up.
With Workers static assets, you just add code to the same project.
{
"name": "my-static-site",
"main": "src/index.js",
"compatibility_date": "2026-08-20",
"assets": {
"directory": "./dist",
"binding": "ASSETS"
}
}Add main and specify binding. Then write the code.
export default {
async fetch(request, env) {
const url = new URL(request.url);
// Handle only URLs starting with /api/ ourselves
if (url.pathname.startsWith("/api/")) {
return Response.json({ message: "This is a response from the API" });
}
// Return static files for everything else
return env.ASSETS.fetch(request);
},
};The static site and the API live together in one project. Connect D1 and it becomes a site with a database; connect Workers AI and it gains AI features.
If you add a form, the standard combination is Turnstile for spam protection and Email Routing if you want to receive submissions by email.
Cost and limits#

Access to static files is free#
Requests for static files are free and unlimited. Storing the files costs nothing either. Whether it’s a personal site or one with a fair amount of traffic, this part never generates a bill.
The only thing billed is requests where Worker code runs. On a purely static site, no code runs.
Limits you should know#
| Item | Free | Paid |
|---|---|---|
| Files per version | 20,000 | 100,000 |
| Size per file | 25MiB | 25MiB |
Rules in _headers | 100 | 100 |
Total in _redirects | 2,100 | 2,100 |
The file count limit can become a problem on sites with lots of images. If you’re hosting tens of thousands of photos, as in a photo gallery, consider moving just the images to R2.
The 25MiB-per-file limit catches video files. Large videos shouldn’t be served as static assets in the first place.
Points beginners should watch out for#
directorypoints to the build output: If you specify the source folder, files like.mdget published as-is. Specify the folder produced by the build- Don’t forget
not_found_handlingfor SPAs: This is almost always the cause of “the top page loads, but direct links give a 404” - Don’t put secret files in it: Everything in the folder you specify as
directoryis published. Before deploying, check that no.envor backup files have slipped in - Check that caches have updated: If you see old content after an update, it’s either the browser cache or Cloudflare’s cache. Check in a private window, and purge from the dashboard if necessary
- No need to rush migrating from Pages to Workers: Pages projects that are already running can keep being used as they are
- Preview URLs are public too: The URL created for each pull request can be opened by anyone who knows it. If it contains unreleased information, protect it with Cloudflare Access
wrangler deploygoes straight to production: If you want an extra check step, using the preview feature of the GitHub integration is safer
Related services#
- What Is Cloudflare Pages?: The other option and how it differs
- What Is Cloudflare Workers?: The basics for adding dynamic processing
- Your First Workers Project: How to use Wrangler (a prerequisite for this page)
- What Is R2?: For hosting large numbers of images or videos
- What Is Turnstile?: Spam protection for contact forms
- What Is a CDN?: Why delivery is fast
Summary#
- For new static sites, Workers static assets is recommended. Pages remains available
- Write
assets.directoryinwrangler.jsoncand runnpx wrangler deploy, and you’re published. No code needed - Connect GitHub and pushes deploy automatically, with a preview URL created for each pull request
- For a custom domain, just add
custom_domain: trueinroutes. DNS and certificates are automatic - For SPAs, always specify
not_found_handling: "single-page-application" - Requests for static files are free and unlimited. You’re billed only when Worker code runs
- The file count limit is 20,000 on Free / 100,000 on Paid, with up to 25MiB per file
- Add
mainandbindinglater and an API can live in the same project
No server contract, no FTP uploads, no certificate renewals, and your site is delivered worldwide. Publishing a static site is the lowest-barrier entry point to Cloudflare, with results that are easy to see.
On the next page, we’ll create an email address on your own domain without running a server.