Skip to content

fix(cli): serve the embedded web UI brotli-compressed - #53645

Merged
Hona merged 1 commit into
brotli-max-qualityfrom
serve-brotli
Oct 7, 2026
Merged

Hona merged 1 commit into
brotli-max-qualityfrom
serve-brotli

Conversation

@Hona

@Hona Hona commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

The server's HttpMiddleware.compression() already brotli-compresses responses, but for embedded assets that meant two steps on every request: decompress the archive's brotli body, then compress it again at the middleware's level 4. Fonts weren't compressed at all, because font/ttf isn't on the middleware's compressible list. Now a browser that accepts br gets the archive's quality-11 bytes as they are.

flowchart LR
  subgraph Before
    A[embedded br q11] -->|decompress| B[raw asset] -->|"compress br q4<br/>(fonts: none)"| C[browser]
  end
  subgraph After
    D[embedded br q11] -->|"Content-Encoding: br"| E[browser]
  end
Loading

Loading every web UI asset (1,691 files) from the Windows x64 CLI with Accept-Encoding: gzip, deflate, br:

Before (#53644) This PR
JS, CSS, HTML sent 7.8 MB 6.5 MB
Fonts sent 17.9 MB 8.3 MB
WASM sent 12.0 MB 8.7 MB
Total sent 38.2 MB 23.9 MB
Time to serve all 1.7 s 0.3 s
CLI / desktop installer size 203.8 / 241.4 MB 203.8 / 241.4 MB
  • index.html is still sent decoded, because its CSP hashes the inline theme script. The middleware compresses it as before.
  • A client that doesn't accept br, or sends br;q=0, still gets decoded bytes. The middleware leaves any response that already has a Content-Encoding untouched.
  • Both kinds of asset response carry Vary: accept-encoding.
const encoded = key !== "index.html" && acceptsBrotli(request.headers["accept-encoding"]) ? brotli?.[key] : undefined
const requested = encoded ?? assets[key]

Copilot AI balanced review requested due to automatic review settings October 7, 2026 01:13
@Hona
Hona added this pull request to stack #53646 October 7, 2026 01:13

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Browsers that accept brotli now get each asset's embedded bytes as they are, with Content-Encoding: br, instead of a body the server decompressed on every request. The HTML stays decoded for its CSP hash, and other clients still get decoded bytes, with Vary: accept-encoding on both.
@Hona
Hona merged commit a90ad85 into v2 Oct 7, 2026
11 of 13 checks passed
@Hona
Hona deleted the serve-brotli branch October 7, 2026 01:35
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.

2 participants