fix(website): don't let the asset and image proxies veto their own Cache-Control
Problem
website/loaders/asset.ts (font/asset proxy) and website/loaders/image.ts return a Response that sets
Cache-Control: public, s-maxage=15552000, max-age=15552000, immutable. Neither module exports cache, so
the loader defaults to no-store. Since deco 1.205 a no-store loader sets vary.shouldCache = false, and the
runtime middleware then overwrites the response header with no-store, no-cache, must-revalidate.
Result: proxied fonts (/live/invoke/website/loaders/asset.ts?src=https://fonts.gstatic.com/...) and images are
never kept by the CDN or the browser. Every page view refetches every proxied font through the origin. Entries
cached before the deco upgrade keep hitting until they expire, which hides the problem at first.
Fix
export const cache = "no-cache" on both loaders: the loader cache still skips them (they return a stream), but
they no longer veto, so their own Cache-Control survives. Same pattern as #1712.
image.ts had a module-level const cache (its Cache API handle); it is renamed to imageCache to make room for
the export. No other behavior change.
Tested
deco 1.217.0 + apps 0.170.0, a site that proxies Google Fonts through asset.ts, with this branch through a local
import-map override:
| Request | Before | After |
|---|---|---|
asset.ts?src=<gstatic .ttf> | 200, no-store, no-cache, must-revalidate | 200, public, s-maxage=15552000, max-age=15552000, immutable |
image.ts?src=<png>&width=64 | 200, no-store, … | 200, public, s-maxage=15552000, … |
asset.ts?src=<missing gstatic file> | 500, no-store | 500, no Cache-Control (as before deco 1.205) |
asset.ts?src=http://169.254.169.254/x | 403 | 403 |
| HTML page | unchanged | unchanged |
deno check on both files shows only the two existing website/utils/crypto.ts errors, which are also on main.
🤖 Generated with Claude Code
Summary by cubic
Fixes the asset and image proxies so their own Cache-Control headers are no longer overwritten with no-store, restoring CDN and browser caching for proxied fonts and images on deco 1.205 and later.
- Both loaders now export
cache = "no-cache", which keeps them out of the loader cache without vetoing the response's cache decision. image.tsrenames its module-level Cache API handle toimageCacheto make room for the export; no behavior change.
Summary by CodeRabbit
- Bug Fixes
- Updated caching behavior for asset and image responses. These responses are now marked as requiring cache revalidation, helping ensure cached content is checked before it is reused.