WebAssembly (Wasm)
A binary instruction format that enables near-native performance in web browsers by running code compiled from languages like Rust, C++, and Go.
Detailed Explanation
WebAssembly is a low-level, assembly-like language that runs at near-native speed in the browser. It allows developers to write performance-critical code in languages like Rust, C, C++, and Go, compile it to Wasm, and run it alongside JavaScript in the browser.
Wasm is used for: image/video editing (Figma uses Wasm), CAD tools (Onshape), games (Unity WebGL), cryptography, scientific computing, and runtimes (Deno runs Wasm). Outside the browser, Wasm is used in server-side applications (Wasmtime, Wasmer) for sandboxed, portable code execution.
Why It Matters
Wasm enables near-native performance in the browser, opening possibilities that were impossible with JavaScript alone.
Real-World Example
Figma uses WebAssembly to render complex vector graphics in the browser. Without Wasm, their collaborative design tool would be too slow to be practical in a web browser.
When to Use
When you need near-native performance in the browser (image processing, CAD, games), port existing C/C++/Rust code to the web, or need sandboxed code execution on servers.
Advantages
- Near-native performance in the browser
- Supports multiple source languages (Rust, C++, Go)
- Runs alongside JavaScript
- Sandboxed and secure
- Portable across platforms and browsers
Disadvantages
- Debugging is harder than JavaScript
- Limited access to browser APIs
- Binary format is not human-readable
- Growing but still maturing ecosystem
- Compilation toolchain complexity
Related Terms
Frequently Asked Questions
Do I need to learn WebAssembly?
Not immediately. JavaScript is sufficient for most web development. Learn Wasm when you need near-native performance (image processing, CAD, games) or want to port existing C/C++/Rust code to the web.
Is WebAssembly replacing JavaScript?
No. Wasm complements JavaScript. JavaScript handles DOM manipulation, UI logic, and general-purpose programming. Wasm handles performance-critical computation. They work together, not as replacements.
What languages compile to WebAssembly?
Rust (best tooling via wasm-pack), C/C++ (Emscripten), Go (tinygo), AssemblyScript (TypeScript-like), and C# (Blazor). Rust is the most recommended for new Wasm projects.
Can WebAssembly access the DOM?
Not directly. Wasm communicates with JavaScript to manipulate the DOM. Wasm handles computation; JavaScript handles UI updates. Some frameworks (Yew, Leptos) abstract this for Rust developers.
Is WebAssembly faster than JavaScript?
For CPU-intensive tasks, yes—Wasm can be 2-10x faster. For DOM manipulation and I/O, JavaScript is often faster due to V8 optimizations. Wasm excels at computation, not at interfacing with browser APIs.