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 #1033

Closed opened this
Closed without merging

Every page now links the shell's script (shellJs, about 27.7 KB) as a cached file at /assets/shell- .js instead of sending it inline. Each HTML response is about 27.5 KB smaller, and a browser downloads the shell once per deploy. Why the last check failed.

Notes

stopped closed without shipping deploy c962028

opened this

Every page now links the shell's script (shellJs, about 27.7 KB) as a cached file at /assets/shell-<hash>.js instead of sending it inline. Each HTML response is about 27.5 KB smaller, and a browser downloads the shell once per deploy.

Why the last check failed. The check parked on pull #1004 failed in "capacity: only a forge admin reads or changes it > an admin changes each one…". That test fails on main too, whenever FORGE_CHECK_SHARDS is set. The check command sets it to 2 for its shard runner, and test processes inherit it. That variable is also the boot default for checks.shards, so resetting the setting went back to "2" instead of to nothing. Commit c962028 clears the variable for that describe block and restores it afterwards. This is the cause #1018 left unnamed, so it may conflict with #1018's split of the same case.

The check's other failures were preview deploys that didn't come up in time, an egress probe refused, and looks that depend on a deploy, all in a check that ran 21 minutes. Run here with FORGE_CHECK_SHARDS=2, those suites all pass on this branch: studio 175, fork-pull-approval 12, meter 7, looks 14, contain 25.

What changed for the shell (2fd49ba)

  • src/web/asset.ts: shellAsset() hashes shellJs once per process and returns its path and an integrity hash. shellResponse() serves it with cache-control: public, max-age=31536000, immutable.
  • src/http/server.ts: the existing /assets/:name.js route serves the shell as well as the highlighter. A stale hash gets a 404, and that page works without the shell's scripting until it reloads.
  • src/web/layout.ts: page() emits <script nonce src integrity> for the shell, then the page's own scriptJs inline under the same nonce.

Run order: the shell is a classic script, not a module and not deferred, placed directly before the page's inline script. Classic scripts run in document order, so the page's script still runs after the shell. The shell is a self-contained IIFE and defines no globals.

CSP: the nonce admits the file, so script-src gains neither 'self' nor 'unsafe-inline'.

Tests:

  • New, in test/web.test.ts:
    • On the studio /, the shell's source is absent from the HTML, it is linked as a classic script with the nonce and integrity, and it comes before the page's inline script.
    • The served file is immutable, byte-for-byte shellJs, and matches its integrity hash; a stale hash gets a 404.
  • Changed, because they asserted the old inline shape:
    • The palette test now reads the scorer from the linked file.
    • test/web-browse.test.ts now allows the shell's file as the only <script src>.

The shell isn't minified; that was left out on purpose.

To try it: open a page on the preview and find the shell-….js tag at the end of <body>. On the second load the file comes from cache, and the palette, Escape on menus and the theme menu work as before.

🤖 Generated with Claude Code

Closes #114

commented

Parked by the crew: the check failed ("every open pull's preview on the studio page > a change's page names its preview's data as its own copy and gives the moment it was taken; production's card does not") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs