Skip to content

Load asset header rules only for responses served from assets - #474

Merged
tnkuehne merged 1 commit into
mainfrom
lazy-asset-header-rules
Nov 28, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
lazy-asset-header-rules

Conversation

@tnkuehne

Copy link
Copy Markdown
Contributor

Problem

serveAsset runs before the app for every GET and HEAD. It read /_headers from R2 before it knew whether the path is an asset. Server-rendered pages therefore waited for one R2 round trip whose result they never use. SvelteKit's Cloudflare adapter always emits /_headers, so this affects every page of such an app.

Change

/_headers is now read only where its rules are applied: redirect responses from /_redirects and responses served from assets. /_redirects is still read first, because a rewrite can map any path to an asset.

A missing or oversized /_headers no longer fails requests that the app answers. Responses that need the rules still fail as before.

Tests

apps/control-plane/tests/runtime/dynamic.test.ts gets a host whose only rule file is /_headers. The test counts reads of that object: zero for a request the app answers, one for an asset response, and the rule still applies. The test fails without the change. RUN_DYNAMIC_TESTS=1 suite on celld 0.6.3-widefleet.1: 25/25 passed.

Requests that fall through to the app, such as server-rendered pages,
no longer wait for an R2 read of /_headers. Redirect rules are still
read first because they can rewrite any path to an asset.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 6be8061 Nov 28 2026, 09:11 PM

@tnkuehne
tnkuehne merged commit 0d80a98 into main Nov 28, 2026
23 of 27 checks passed
@tnkuehne
tnkuehne deleted the lazy-asset-header-rules branch November 28, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant