惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
C
Check Point Blog
博客园 - Franky
月光博客
月光博客
T
Tenable Blog
博客园 - 聂微东
Cyberwarzone
Cyberwarzone
The GitHub Blog
The GitHub Blog
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
IT之家
IT之家
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
F
Full Disclosure
博客园 - 司徒正美
Project Zero
Project Zero
Y
Y Combinator Blog
A
Arctic Wolf
美团技术团队
博客园 - 叶小钗
S
Securelist
F
Fortinet All Blogs
T
Threatpost
T
Threat Research - Cisco Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Schneier on Security
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
P
Privacy International News Feed
博客园_首页
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
P
Proofpoint News Feed
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
雷峰网
雷峰网
P
Proofpoint News Feed
Latest news
Latest news
G
GRAHAM CLULEY

Flavio Copes

Better Auth: an introduction Cloudflare Artifacts: Git storage built for AI agents Workers Cache: a cache in front of your Cloudflare Worker Cloudflare Drop: drag a folder, get a live site Temporary Cloudflare accounts: agents can now deploy without signing up Moondream 3.1 on Workers AI: fast vision at the edge inferencecost.dev: what will AI inference cost you at 10k users? Sitebase: all the features your website needs, in one place StackPlan: figure out where to deploy your app, and what it How the Cloudflare Pages build cache works The Summer of Code How I generate an Open Graph image for every post New: 90 free tools for developers How I added search to my static site with Pagefind How to rebuild a Cloudflare site on a schedule Cloudflare Email Workers: run code when an email arrives Cloudflare Turnstile: stop bots without annoying CAPTCHAs Cloudflare Workers: secrets and environments Cloudflare Workers observability: logs and traces Cloudflare Analytics Engine: store and query metrics The AI Workshop (July 2026 cohort) Cloudflare Cron Triggers: run a Worker on a schedule Cloudflare Durable Objects: state that lives in one place Cloudflare Queues: run work in the background Cloudflare R2: object storage without egress fees Cloudflare KV: a key-value store for your Workers Cloudflare D1: a SQL database for your Workers Wrangler: the Cloudflare Workers command line tool Executor: one gateway to connect your AI agent to every tool Cloudflare Workers: your first serverless function Vercel eve: an open framework for building AI agents Flue: the open framework for building AI agents Val Town: write and deploy code in seconds A hands-on guide to The Agency, a collection of AI agents The AI Workshop (June 2026 cohort) The AI Workshop (May 2026 cohort) The AI Workshop (Apr 2026 cohort)
Serving a website with Cloudflare Workers static assets
Flavio Copes · 2026-06-22 · via Flavio Copes

By Flavio Copes

How to deploy a static site, an SPA, or a full Astro app on Cloudflare Workers using the static assets feature, with a Worker for the dynamic parts.

~~~

A Worker can do more than answer API calls. It can serve a whole website.

Cloudflare calls this static assets. You point a Worker at a folder of files, and Cloudflare serves them fast from the edge, for free. Your Worker code only runs when you need something dynamic.

This is how I serve real apps: static HTML, CSS, and JavaScript handled automatically, with a Worker behind it for the API and anything that needs logic.

The simplest case: just files

Say you have a folder called public with an index.html and some assets. Point your config at it:

{
  "name": "my-site",
  "compatibility_date": "2026-06-20",
  "assets": {
    "directory": "./public"
  }
}

Deploy, and the whole folder is live:

npx wrangler deploy

No Worker code needed. Cloudflare serves the files directly. For a plain static site, that’s the whole story.

Handling URLs that don’t match a file

What happens when someone visits a URL that isn’t a file? You control that with not_found_handling.

For a normal site with custom 404s:

{
  "assets": {
    "directory": "./public",
    "not_found_handling": "404-page"
  }
}

This serves your 404.html when nothing matches.

For a single-page app, where the client-side router handles every route, you want all unknown paths to load index.html instead:

{
  "assets": {
    "directory": "./dist",
    "not_found_handling": "single-page-application"
  }
}

Now React Router, or whatever you use, takes over on the client.

Adding a Worker for dynamic parts

Most apps need some server logic, like an API. You add a main Worker alongside the assets, and a binding so your Worker can reach the files:

{
  "name": "my-app",
  "main": "src/index.ts",
  "compatibility_date": "2026-06-20",
  "assets": {
    "directory": "./dist",
    "binding": "ASSETS"
  }
}

By default, Cloudflare tries to serve a static file first, and only runs your Worker if no file matches. That’s usually what you want.

But sometimes you want your Worker to run first, for example to check authentication before serving anything. Use run_worker_first with the routes that should hit the Worker:

{
  "assets": {
    "directory": "./dist",
    "binding": "ASSETS",
    "run_worker_first": ["/api/*"]
  }
}

Now /api/* always goes to your Worker, and everything else tries static files first.

Deploying an Astro app

This site, and the apps I build, run on Astro. Astro has an official Cloudflare adapter that wires all of this up for you.

Install it:

npx astro add cloudflare

This sets the adapter so Astro builds a static client folder plus a Worker for any server-rendered routes. Then you build and deploy with Wrangler:

npx wrangler deploy

You get the best of both: static pages served straight from the edge, and server routes running in a Worker, all from one deploy.

Why I like this

The old way was to pick: static host or a server. With Workers static assets you get both, in one place, with one deploy command.

Static files are served for free and fast. Your Worker only runs, and only costs, when there’s real work to do.

The details are in the static assets docs.

~~~

Related posts about cloudflare: