Public: anyone can read this; the crew can change it.
The shell's 27 KB of JavaScript is a cached file, not re-sent with every page #1004
The shell's script (shellJs, 27.7 KB) is no longer sent inline with every page. It is now a cached file at /assets/shell- .js, and each page links it, so every HTML response is about 27.5 KB lighter. A browser fetches the shell once per deploy.
stopped closed without shipping deploy 2fd49ba
Sign in to join this conversation.
new above
offline
The shell's script (
shellJs, ~27.7 KB) is no longer sent inline with every page. It is now a cached file at/assets/shell-<hash>.js, and each page links it, so every HTML response is about 27.5 KB lighter. A browser fetches the shell once per deploy.What moved
src/web/asset.ts: a newshellAsset()hashesshellJsonce per process and gives back its path, its name and anintegrityhash.shellResponse()serves it through the existingassetResponse, withcache-control: public, max-age=31536000, immutable.src/http/server.ts: the existing/assets/:name.jsroute now serves the shell as well as the highlighter bundle. A stale hash still gets a 404, and an old tab falls back to plain HTML until it reloads.src/web/layout.ts:page()no longer joinsshellJsonto the page's own script. It emits<script nonce src integrity>for the shell, then the page's ownscriptJsinline under the same nonce, only when the page has one.How the run order is kept: the shell is linked as a classic script, not a module and not deferred, placed just before the page's inline script. Classic scripts run in document order, so the page's script still runs after the shell, as it did when they were one block. The shell is a self-contained IIFE that defines no globals. The cost is that the shell blocks parsing at the end of
<body>on first load. After that it comes from cache.CSP: the external tag carries the page's nonce, so
script-srcdoes not gain'self'and no page gains'unsafe-inline'. The highlighter is still the only thing that relaxes the policy, and the integrity hash pins the shell's bytes.Tests
test/web.test.ts:/, the shell's source is not in the HTML (andshellJsis over 25 KB).'unsafe-inline'and no'self'.shellJs, and matches its integrity hash; a stale hash gets a 404.fuzzyScore/openModalfrom the linked file instead of the HTML.test/web-browse.test.tsnow allows the shell's file as the only<script src>.--timeout 60000(what the forge's check uses), the web, browse, editor, palette, UI, code, studio, live, board and adversarial-CSP suites all pass (385 tests). Under bun's default 5 s hook timeout, the setup ofstudio-wordsandweb-browsetimed out on this machine; the base branch fails the same way.Not done: the shell isn't minified. It is served as written, and gzip covers most of the gain. I left
docs/DESIGN.mdalone because its line about CSP is still true.To try it: open any page and see
<script nonce=… src="/assets/shell-….js" integrity=…>at the end of<body>. On a second load the file is served from cache, and the palette (⌘K), Escape on menus and the theme menu all work as before.🤖 Generated with Claude Code
Closes #114