Web: WebAssembly build served cross-origin isolated, immutable and precompressed
The web app is built with --wasm (skwasm, JS/CanvasKit fallback beside it). The proxy serves it with COOP same-origin + COEP credentialless so skwasm renders on a worker; an installed build loads from /_v/<buildId>/ cached as immutable, other files revalidate by ETag, and the installer precompresses .br/.gz variants the proxy sends by Accept-Encoding. The bootstrap no longer registers Flutter's deprecated service worker (a reload per install). Read aloud on the web uses the Web Speech API through package:web: the flutter_tts web plugin's interop casts fail under wasm. Bench kit: isolation and headed modes, renderer and memory reporting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+21
-1
@@ -46,7 +46,9 @@ SOURCES = {
|
||||
SKIPPED = {"build", ".dart_tool", ".gradle", ".cxx", "local.properties", ".DS_Store", "ephemeral", "Pods", ".symlinks"}
|
||||
# This is part of the web cache key so entries made before release metadata was
|
||||
# generated cannot be mistaken for complete web releases.
|
||||
WEB_CACHE_SCHEMA = "web-release-metadata-v1"
|
||||
# v2: WebAssembly beside JavaScript, precompressed (.br/.gz) assets.
|
||||
WEB_CACHE_SCHEMA = "web-wasm-precompressed-v2"
|
||||
PRECOMPRESS = Path(__file__).with_name("precompress_web.mjs")
|
||||
WEB_RELEASE_SCHEMA = 1
|
||||
VERBOSE = False
|
||||
|
||||
@@ -61,6 +63,7 @@ def digest(kind, app=APP, extra=()):
|
||||
hasher.update(kind.encode())
|
||||
if kind == "web":
|
||||
hasher.update(b"\0cache-schema\0" + WEB_CACHE_SCHEMA.encode())
|
||||
hasher.update(b"\0precompress\0" + PRECOMPRESS.read_bytes())
|
||||
if kind in ("linux", "macos"):
|
||||
hasher.update(b"\0cache-schema\0desktop-v1")
|
||||
for script in (Path(__file__), Path(__file__).with_name("app_desktop_build.py")):
|
||||
@@ -216,6 +219,7 @@ def build(kind, runner=subprocess.run, app=APP, cache=None, arguments=(), log=pr
|
||||
(work / "data/flutter_assets").is_dir() and (work / "lib").is_dir()):
|
||||
raise RuntimeError("Linux build did not produce its complete executable/data/lib bundle")
|
||||
if kind == "web":
|
||||
precompress_web(work, runner, log)
|
||||
(work / "release.json").write_text(json.dumps(web_release_metadata(key)) + "\n")
|
||||
(work / ".complete").write_text(json.dumps({"key": key, "built": built}) + "\n")
|
||||
if entry.exists():
|
||||
@@ -228,6 +232,22 @@ def build(kind, runner=subprocess.run, app=APP, cache=None, arguments=(), log=pr
|
||||
return entry
|
||||
|
||||
|
||||
def precompress_web(directory, runner=subprocess.run, log=print):
|
||||
"""Writes the .br/.gz variants the web proxy serves (precompress_web.mjs).
|
||||
|
||||
Node runs the web proxy, so an installation has it; without it the build
|
||||
is still complete and is served uncompressed."""
|
||||
node = shutil.which("node")
|
||||
if not node:
|
||||
log("Node.js was not found; the web app is served uncompressed.")
|
||||
return
|
||||
result = runner([node, str(PRECOMPRESS), str(directory)], capture_output=True, text=True)
|
||||
if result.returncode:
|
||||
raise RuntimeError("precompressing the web build failed: " + (result.stderr or "").strip()[-300:])
|
||||
if VERBOSE and result.stdout:
|
||||
log(result.stdout.strip())
|
||||
|
||||
|
||||
def prune(cache, kind, keep):
|
||||
entries = sorted((p for p in cache.glob(f"{kind}-*") if (p / ".complete").is_file()),
|
||||
key=lambda p: p.stat().st_mtime, reverse=True)
|
||||
|
||||
Reference in New Issue
Block a user