返回综合榜
开发工具与框架Mozilla Hacks

为什么 WebAssembly 在 Web 上仍是二等公民语言

Mozilla Hacks 发布文章(由 2025 年慕尼黑 WebAssembly CG 会议上的演讲扩展而来),指出 WebAssembly 在 Web 上普及受限的根源在于它是二等公民语言:只能通过 JavaScript 访问 Web 平台 API,导致开发者体验不佳。

加载 Wasm 十分繁琐,因为 script 标签不支持 Wasm,需要使用 JS API 中晦涩的实例化流程;不过 esm-integration 提案已由打包工具实现,Firefox 也正在实现,可通过 JS 模块系统导入 Wasm 模块。使用 Web API 的问题更大:一次 console.log 调用就需要生成的 JS 胶水代码在 Wasm 内存与 JS 对象之间重新编码数据,给构建带来语言特定的复杂性,并在边界处产生运行时开销。

文章列出四个后果:编译器必须生成配套的 JS 胶水代码,而 Clang/LLVM 等上游工具链不愿维护,导致标准编译器产出的 Wasm 不能直接在 Web 上运行,用户只能寻找非官方工具链发行版;Web 文档面向 JavaScript 开发者;通过胶水代码调用 Web API 依然缓慢,作者引用 2020 年 TodoMVC 基准测试对比了 JS 胶水与直接 DOM 绑定的性能。作者总结称 JavaScript 往往更简单且够用,只有大公司才值得投入,并提出 WebAssembly Components 是改进方向。

Why WebAssembly Is Still a Second-Class Language on the Web

Mozilla Hacks published an article, expanded from a 2025 WebAssembly CG meeting talk in Munich, arguing that WebAssembly's limited adoption on the web stems from it being a second-class language: it can only reach web platform APIs through JavaScript, which results in a poor developer experience.

Loading Wasm is cumbersome because it is not supported in script tags and requires the JS API's arcane instantiation sequences, though the esm-integration proposal, already implemented in bundlers and actively being implemented in Firefox, allows importing Wasm modules via the JS module system. Using Web APIs is worse: a single console.log call requires generated JS glue code that re-encodes data between Wasm memory and JS objects, adding language-specific build complexity and runtime costs at the boundary.

The article lists four consequences: compilers must generate companion JS glue that upstream toolchains like Clang/LLVM don't want to maintain, so standard compilers don't produce web-ready Wasm and users must find unofficial toolchain distributions; web documentation is written for JavaScript developers; and calling Web APIs through glue remains slow, illustrated by a 2020 TodoMVC benchmark comparing Wasm with JS glue against direct DOM bindings. The author concludes that JavaScript often feels simpler and good enough, so only large companies justify the investment, and suggests WebAssembly Components as the path forward.

WebAssemblyJavaScriptweb platformglue codeesm-integrationWebAssembly ComponentsMozillaFirefox
综合12
质量86
猎物热度0
时效0
信息来源1 个来源,主来源:Mozilla Hacks

猎鹰不保存原文正文。标题与摘要用于快速发现信息,事实细节请以来源原文为准。

查看来源