Skip to content

Package precompressed assets for the split web image - #2512

Open
n30nex wants to merge 2 commits into
Kpa-clawbot:masterfrom
n30nex:codex/split-assets-20261129
Open

n30nex wants to merge 2 commits into
Kpa-clawbot:masterfrom
n30nex:codex/split-assets-20261129

Conversation

@n30nex

@n30nex n30nex commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2505.

The split web image prepares Brotli and gzip sidecars after writing its deployment descriptor and cache-busted HTML. Caddy negotiates the sidecars. Dynamic encoding remains available for other responses. Node.js is confined to the image’s packaging stage.

This is a selective cherry-pick of Beacon’s precompression commit. The standalone .build/compress-assets.mjs tool now lives in scripts/static/beacon/, with its original AGPL-3.0-or-later license, author credit and commit trailer. The adaptation processes one file at a time. The ordinary static build still succeeds without Node.

Across 144 identical packaged files, actual Caddy HTTP response body totals were:

Client accepts Before After
gzip, deflate, br, zstd 2,016,659 B 1,625,412 B
br 6,185,699 B 1,638,910 B
gzip 1,987,553 B 1,910,120 B
identity 6,185,699 B 6,185,699 B

All 1,152 responses decoded to the original bytes. The 264 sidecars added 3,006,398 bytes. Median packaging time over three runs rose from 0.44 s to 13.03 s. The browser-profile transfer reduction was 19.4% across the full asset set.

Verified with Alpine Caddy, Edge, 33 packaging tests and 10 web-container checks. Tests before the fix

Select .build/compress-assets.mjs from @MrAlders0n's Beacon change and
carry its original LICENSE into scripts/static/beacon/. Process one
asset at a time to bound compressor memory during packaging. Caddy
serves the resulting sidecars alongside their canonical originals.

Source: MeshCore-Beacon/beacon-web@68fd615

(cherry picked from commit 68fd61574b6cc6559e32e5285a650cbab87dc7e3)
@n30nex

n30nex commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Kent Beck Gate: PASS (test quality) at adbcf1c9c. The test runs the packager and decodes Brotli and gzip back to the original shipped bytes. It also checks nested files, generated HTML and assets too small to benefit. Caddy served all 144 assets across four browser encoding profiles. In a connected browser the backend reported 502 observations and the WebSocket opened.

@n30nex
n30nex marked this pull request as ready for review November 29, 2026 18:14

@zfouts zfouts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at adbcf1c9. Approving. The ordering is right and the test proves it.

  • Compression runs last in scripts/static/build.sh, after the __BUST__/__CORESCOPE_URL__ fill, the deployment.js rewrite and the byte checks, so a sidecar can't be stale.
  • test-static-build.js decodes every sidecar and compares it with a build without PRECOMPRESS. It would fail if compression ran before the substitutions.
  • Two PRECOMPRESS=true builds give identical trees (diff -r, 132 .br + 132 .gz).
  • Against Caddy 2.11.9 (what apk add caddy installs on alpine:3.24) with this Caddyfile: correct Content-Encoding, Content-Type and Vary; a separate ETag per encoding; 304 for a matching If-None-Match; the @nocache headers still apply; and encode doesn't re-compress a sidecar.
  • test-static-build.js 33/33 and test-web-container.js 10/10 pass locally.

Notes, none blocking:

  1. Licence (maintainer's call). scripts/static/beacon/compress-assets.mjs is AGPL-3.0-or-later and brings a 661-line AGPL LICENSE into this GPLv3 repo. GPLv3 §13 allows that, and the script is a build tool that is never served, but the maintainer should accept it deliberately. A clean-room rewrite of the ~35 lines would avoid the question.
  2. Caddy version. Dockerfile.web doesn't pin Caddy. With this Caddyfile, caddy:2.10.2 answers a plain GET (no Range header) with 206 whenever a sidecar exists; 2.11.9 is fine. A comment in docker/web/Caddyfile naming the minimum version would save someone reusing it.
  3. Cloudflare limits. The file-count and 25 MiB checks (build.sh:134-138) run before compression, so PRECOMPRESS=true with a Pages deploy (about double the files, and Pages ignores the sidecars) isn't checked. Documenting PRECOMPRESS as web-image-only, or refusing it unless API_BASE=same-origin, would close that.

@zfouts

zfouts commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Following up on the licence note in my review: n30nex#31 is a PR into this branch. It replaces scripts/static/beacon/compress-assets.mjs and its AGPL LICENSE with scripts/static/precompress.js, written for CoreScope under GPLv3.

  • On a full packaging of public/, the two scripts produce byte-identical trees.
  • Dockerfile.web and the Caddyfile are untouched.
  • test-static-build.js gains a reproducibility check and a check that nothing under scripts/static is AGPL-licensed.

If you merge it into codex/split-assets-20261129, #2512 no longer adds an AGPL file to the repo.

@efiten

efiten commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks @n30nex. The packaging itself looks right: only .br/.gz copies of unchanged files, written after the __BUST__ fill and deployment.js, Node confined to the build stage, no npm dependency, and the new tests fail on master.

One thing before merging: CoreScope is GPL-3.0, and I'd rather keep a single licence in the repo than carry an AGPL-3.0 file with its own LICENSE under scripts/static/beacon/. Your n30nex#31 does exactly that, with byte-identical output and a test that rejects AGPL files under scripts/static. Could you push it onto this PR's branch? I'll merge once CI is green on that head.

Non-blocking, for this PR or a follow-up:

  • The CI smoke in deploy.yml fetches assets with curl without Accept-Encoding, so it never receives a sidecar. A request with Accept-Encoding: br that checks Content-Encoding: br would cover the negotiation.
  • PRECOMPRESS is not mentioned in docs/deployment.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serve precompressed static assets from the split web image

3 participants