Skip to content

Static Assets

把静态文件冻进同一份不可变 deployment。配置在 assets

json
{
  "name": "site",
  "main": "src/index.ts",
  "assets": {
    "directory": "./public",
    "binding": "ASSETS",
    "run_worker_first": false,
    "html_handling": "auto-trailing-slash",
    "not_found_handling": "none"
  }
}

html_handlingauto-trailing-slash(默认)、force-trailing-slashdrop-trailing-slashnonenot_found_handlingnone(默认)、404-pagesingle-page-applicationrun_worker_first 可以是 boolean,或一组以 / / !/ 开头的路径规则。Assets-only 项目省略 main,也不能声明执行环境或 Worker-first。

可选 publish_source_maps。binding 存在时,env.<binding>.fetch() 只取资源,不进入租户 Worker。

兼容性

主题Cloudflareopen-compute
HTML trailing slash、SPA、Worker-first、_headers / _redirects 路由概念是,见 Cloudflare Static Assets对齐
对象存储全球 CDN本机不可变 S3 对象,不是全球 CDN
全球 CDN placement / 复制 / purge 传播 / 产品配额不提供
Pages 产品迁移向导不提供