[GH-ISSUE #5082] Capability package client bundles re-download in full on every app load (no ETag/304 anywhere) #2811

Closed
opened 2026-10-21 05:56:02 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Aug 15, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5082

Originally assigned to: @kolacheee on GitHub.

What happens

Every installed Agent package's client bundle is fully re-downloaded on every app load. The server sends Cache-Control: no-cache, must-revalidate on /api/capability-packages/:id/client but never sends an ETag or Last-Modified — and no-cache means "revalidate before using", so with nothing to revalidate against, the browser has to re-fetch the whole body every time. The same applies to /api/capability-packages/:id/assets/*.

For anyone with World Maps installed that's the full hierarchical-maps client bundle on every single app open, on every platform — phones included. It also makes bundle size a per-boot tax for any future package that ships more client code or art.

Try it yourself

  1. Install any Agent package (World Maps / hierarchical-maps is the common one).
  2. Open DevTools → Network, load the app, find the request to /api/capability-packages/hierarchical-maps/client.
  3. Reload the page. The same request returns 200 with the full body again — never a 304, and the request carries no If-None-Match because the first response had no ETag.

(grep -ri "etag" packages/server/src comes back empty — the server has no cache validators anywhere.)

Why it happens

packages/server/src/routes/capability-packages.routes.ts — the /client handler (~line 74) sends Cache-Control: no-cache, must-revalidate with no validator header; /assets/* (~line 83) sends private, no-cache, must-revalidate the same way.

Suggested fix

Every served package file already has a trusted content hash: manifest.files[] records a sha256 per file, and the serve path re-verifies it on every read. That hash is a perfect strong ETag:

  • /client: send ETag: "<manifest sha256>" and answer If-None-Match with 304. Keep no-cache semantics — a package author can republish the same version with different bytes during development, so the bundle should always revalidate (just cheaply). The client already appends ?v=<version> to the import URL, so the cache key is correct today.
  • /assets/*: same ETag; additionally, when the request's ?v= equals the installed version, the response can be public, max-age=31536000, immutable — the path + version + hash pin the exact bytes.

No client changes needed: the dynamic import() rides the normal browser HTTP cache, and a 304 revalidation is transparent to it.

Found while building a pixel-RPG game-surface Experience (whose art/bundle costs make the per-boot re-download acute); verified against staging @ 068d01fad.

Originally created by @kolacheee on GitHub (Aug 15, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5082 Originally assigned to: @kolacheee on GitHub. ### What happens Every installed Agent package's client bundle is fully re-downloaded on every app load. The server sends `Cache-Control: no-cache, must-revalidate` on `/api/capability-packages/:id/client` but never sends an ETag or Last-Modified — and `no-cache` means "revalidate before using", so with nothing to revalidate against, the browser has to re-fetch the whole body every time. The same applies to `/api/capability-packages/:id/assets/*`. For anyone with World Maps installed that's the full hierarchical-maps client bundle on every single app open, on every platform — phones included. It also makes bundle size a per-boot tax for any future package that ships more client code or art. ### Try it yourself 1. Install any Agent package (World Maps / hierarchical-maps is the common one). 2. Open DevTools → Network, load the app, find the request to `/api/capability-packages/hierarchical-maps/client`. 3. Reload the page. The same request returns `200` with the full body again — never a `304`, and the request carries no `If-None-Match` because the first response had no `ETag`. (`grep -ri "etag" packages/server/src` comes back empty — the server has no cache validators anywhere.) ### Why it happens `packages/server/src/routes/capability-packages.routes.ts` — the `/client` handler (~line 74) sends `Cache-Control: no-cache, must-revalidate` with no validator header; `/assets/*` (~line 83) sends `private, no-cache, must-revalidate` the same way. ### Suggested fix Every served package file already has a trusted content hash: `manifest.files[]` records a sha256 per file, and the serve path re-verifies it on every read. That hash is a perfect strong ETag: - `/client`: send `ETag: "<manifest sha256>"` and answer `If-None-Match` with `304`. Keep `no-cache` semantics — a package author can republish the same version with different bytes during development, so the bundle should always revalidate (just cheaply). The client already appends `?v=<version>` to the import URL, so the cache key is correct today. - `/assets/*`: same ETag; additionally, when the request's `?v=` equals the installed version, the response can be `public, max-age=31536000, immutable` — the path + version + hash pin the exact bytes. No client changes needed: the dynamic `import()` rides the normal browser HTTP cache, and a 304 revalidation is transparent to it. Found while building a pixel-RPG game-surface Experience (whose art/bundle costs make the per-boot re-download acute); verified against `staging` @ 068d01fad.
bsakaguchi 2026-10-21 05:56:02 +07:00
Author
Owner

@kolacheee commented on GitHub (Aug 15, 2026):

Taking this one (agent working from kolacheee's fork) — draft PR up at #5087. Implementation note for anyone reviewing: the ETag is the manifest-recorded per-file sha256 (the same value the serve path re-verifies bytes against on every read), the client bundle deliberately stays no-cache (never immutable) so a republished same-version bundle is picked up immediately, and assets are immutable only when the request pins the installed version with ?v=.

<!-- gh-comment-id:5303831102 --> @kolacheee commented on GitHub (Aug 15, 2026): Taking this one (agent working from kolacheee's fork) — draft PR up at #5087. Implementation note for anyone reviewing: the ETag is the manifest-recorded per-file sha256 (the same value the serve path re-verifies bytes against on every read), the client bundle deliberately stays `no-cache` (never `immutable`) so a republished same-version bundle is picked up immediately, and assets are `immutable` only when the request pins the installed version with `?v=`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#2811
No description provided.