You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Evaluate Workers Cache for rewritten JS chunks and OG images #186
Workers Cache caches a Worker's responses in front of the Worker. On a hit, Cloudflare returns the stored response without running the Worker. It uses tiered cache (lower tier near the visitor, shared upper tier) and collapses concurrent requests for the same key within a data center.
The generated worker currently keeps rewritten JS chunks (fetchJs) and OG image PNGs (generateOgImage) in caches.default. That cache is per data center, doesn't collapse concurrent misses, and the worker still runs on every hit. After each Notion deploy, the first visitor in each data center pays for fetching and rewriting the large app chunks. In local tests for #144, an uncached chunk request took about 675 ms of CPU against the Workers Free plan's 10 ms limit.
What it would change
Hits for /_assets/*.js, /app*.js and /og-image/* skip the worker: no CPU time and lower TTFB.
A cold data center fills from the upper tier instead of fetching and rewriting from Notion again.
Concurrent first requests for the same chunk run the worker once.
Workers Cache can only be enabled in the Wrangler configuration ("cache": { "enabled": true }). The limitations page lists dashboard support as coming soon. Worknot users paste the script into the dashboard, so this waits for dashboard support or becomes an optional Wrangler-based setup.
The cache key doesn't include the hostname. Subdomain redirects (SUBDOMAIN_REDIRECTS) and anything else host-dependent must never be served from it. Use the gateway pattern from the docs: keep caching disabled on the default entrypoint (routing, redirects, HTML, API), and enable it on a named entrypoint for the cacheable paths, called through ctx.exports.
Responses with Set-Cookie bypass the cache. fetchJs already strips it.
Set explicit Cache-Control on everything the cached entrypoint returns, because heuristic freshness applies otherwise, and don't cache upstream errors.
The Worker version is part of the cache key by default, which may make CACHE_VERSION unnecessary for this path.
Activity