feat(converter): x2t WASM 走 gzip 客户端解压,解除 CF Pages 迁移硬阻塞#100
Merged
Conversation
…gration
CF Pages rejects files >25 MiB at deploy; the raw x2t.wasm is 55 MB. Ship
only the ~11 MB x2t.wasm.gz and decompress it in the browser, handing the
bytes to Emscripten via Module.wasmBinary (which then skips its own fetch of
x2t.wasm entirely).
- prepareWasmBinary(): fetch .gz -> detect gzip magic (1f 8b) -> decompress
with native DecompressionStream('gzip') only when still compressed. Some
servers (Vite dev/preview) send Content-Encoding: gzip and the browser has
already decompressed it (bytes start with \0asm); static hosts (CF/GitHub
Pages) send raw gzip. The magic-byte check handles both.
- Drop public/wasm/x2t/x2t.wasm (55M) and x2t.wasm.br (8M); keep .gz + x2t.js.
Verified: both decompression branches compile a valid 54.7M wasm; Playwright
integration confirms x2t runtime initializes and zero requests hit the raw
x2t.wasm; dist has no file >25 MiB; lint + 240 tests pass.
Known follow-up (non-blocking): build:single inlines the raw wasm and needs
updating to inline the .gz instead.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Includes two docs carried in from #98 (privacy-analytics, sw-stale-build) that were never formatted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
迁 Cloudflare Pages 的唯一硬阻塞:CF Pages 单文件上限 25 MiB,而
public/wasm/x2t/x2t.wasm= 55 M,部署时直接被拒。(dist 文件数 336,远低于 2 万上限,无其它阻塞。)方案
x2t.js(Emscripten)一旦发现Module.wasmBinary有值就跳过自己对x2t.wasm的 fetch(源码第 284 行)。于是:x2t.wasm.gz(11M) +x2t.js,删掉x2t.wasm(55M)与x2t.wasm.br(8M)@ranuts/converter在注入 x2t.js 前新增prepareWasmBinary():fetch(.gz)→ 原生DecompressionStream('gzip')解压 → 塞进window.Module.wasmBinary(无新依赖)关键坑:服务器对
.gz处理不一致.gz加Content-Encoding: gzip→ 浏览器已透明解压(体是裸 wasm\0asm)1f 8b)→ 按 magic bytes 探测:是 gzip 才手动解压,已是裸 wasm 就直接用。两种托管都正确。
验证(端到端)
WebAssembly.compileOK(28 exports)onRuntimeInitializedOK;FS/ccall 可用;对x2t.wasm请求 0 次(只请求.gz)find dist -size +25M→ 空(最大文件 11M)lint:ts通过 · 240 tests 全过影响
dist/已 gitignore,CIpnpm install的prepare钩子用新 src 重建遗留(非阻塞)
build:single(单 HTML)靠内联裸 wasm,删裸文件后需改为内联.gz+ 同款解压。非部署链,单列跟进。详见
docs/explorations/2026-07-05-x2t-wasm-gzip-cf-pages.md。🤖 Generated with Claude Code