Static assets get no configurable headers on native Cloudflare deploys of framework apps

已關閉
#647 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

已經有一個關聯 PR 被合併了。

  • #670 來自 @dvkam —— 已合併

評估

難度
4/5
預估耗時
3-5 天
新手友好度
50/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
typescript, vite
領域
cloud

研究方向

Start by tracing uploadAssets, readGeneratedAssetHeaders, and planAssetWorkerBypass for native Cloudflare deploys, then compare their behavior with the TanStack Start asset configuration described here. Check or add coverage for user-authored _headers and fingerprinted assets; done means the reported cache headers are applied to static assets, or the docs accurately describe the limitation.

由索引模型根據 Issue 內容生成。

描述

Summary

A TanStack Start app deployed with void deploy --platform cloudflare serves its static assets without any configurable headers:

  1. A public/_headers file is copied to dist/client/_headers, but it never applies in production. uploadAssets ignores /_headers, and readGeneratedAssetHeaders only sends a file whose first line is Void's generated marker ("A user-authored _headers is not sent on this path").
  2. Void's own immutable caching for fingerprinted bundles never runs either. planAssetWorkerBypass only applies when the built wrangler.json has assets.run_worker_first: ["/**"], and the TanStack Start build has only "assets": { "directory": "../client" }. With the _headers file removed, the build generates no _headers at all.
  3. As a result, hashed files under /assets/ are served with Cloudflare's default Cache-Control: public, max-age=0, must-revalidate. Browsers revalidate every JS and CSS chunk on every page view.

This contradicts two docs pages:

  • guide/edge/static-assets.md ("Native Cloudflare deployments"): "With void deploy --platform cloudflare, generated JavaScript bundles with content fingerprints receive immutable caching."
  • guide/edge/headers.md ("Framework _headers files"): "Void reads _headers files produced by supported frameworks."

Reproduction

  • [email protected], @tanstack/[email protected], Vite 8, deployed with void deploy --platform cloudflare
  • void.config.ts sets cloudflare.cache.enabled, a custom domain route, a D1 binding and no routing options
  • public/_headers:
    /assets/*
      Cache-Control: public, max-age=31536000, immutable
    
  • After deploy, curl -sI https://<site>/assets/<hashed>.js shows cache-control: public, max-age=0, must-revalidate. CSS is the same.

I also tried routing.headers in void.config.ts ('/assets/*': ['Cache-Control: public, max-age=31536000, immutable']). In the local preview (vite preview in workerd), assets still came back with max-age=0, must-revalidate. I didn't deploy that variant, since the assets are served without starting the Worker, so I don't expect the rules to reach them.

Expected

One of these, for framework apps on native Cloudflare deploys:

  • send a user-authored _headers with the asset upload (as Wrangler does),
  • generate the immutable _headers for fingerprinted files even without run_worker_first, or
  • apply routing.headers to static assets.

Failing those, the docs should say framework apps on --platform cloudflare get no asset headers.

Workaround

A Response Header Transform Rule on the zone that sets Cache-Control: public, max-age=31536000, immutable for a 200 under /assets/.

主要語言
TypeScript
星號
627
分支
66
平均合併
14 小時 17 分鐘
30 天內合併 PR
200

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

voidzero-dev/void 的其他 Issue

查看 voidzero-dev/void 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。