πŸ“ Tutorials
Β· 2 min read

What is WebAssembly? A Simple Explanation for Developers


WebAssembly (Wasm) is a binary format that runs in the browser at near-native speed. It lets you take code written in languages like Rust, C, C++, or Go and run it in a web page.

JavaScript is great, but it’s slow for heavy computation β€” image processing, video editing, 3D games, encryption. WebAssembly fills that gap.

How it works

  1. You write code in Rust, C, C++, or Go
  2. You compile it to a .wasm binary file
  3. Your JavaScript loads and runs the .wasm file in the browser
  4. The browser executes it at near-native speed
// Load and run a WebAssembly module
const response = await fetch('module.wasm');
const { instance } = await WebAssembly.instantiateStreaming(response);

// Call a function defined in Rust/C
const result = instance.exports.fibonacci(40);

JavaScript vs WebAssembly

JavaScriptWebAssembly
SpeedFast (JIT compiled)Faster (pre-compiled)
Use caseUI, DOM, general logicHeavy computation
LanguagesJavaScript/TypeScriptRust, C, C++, Go, etc.
DOM accessDirectThrough JavaScript
File sizeText (larger)Binary (smaller)

WebAssembly doesn’t replace JavaScript β€” they work together. JavaScript handles the UI and DOM, WebAssembly handles the heavy lifting.

Real-world examples

  • Figma β€” the design tool runs C++ compiled to Wasm for performance
  • Google Earth β€” 3D rendering in the browser
  • Photoshop Web β€” Adobe ported parts of Photoshop to Wasm
  • AutoCAD β€” runs in the browser via Wasm
  • Game engines β€” Unity and Unreal can export to Wasm
  • SQLite β€” runs entirely in the browser as Wasm

When to use WebAssembly

  • βœ… CPU-intensive tasks (image/video processing, compression)
  • βœ… Porting existing C/C++/Rust code to the browser
  • βœ… Games and 3D graphics
  • βœ… Cryptography and hashing
  • βœ… Scientific computing and simulations
  • ❌ Simple web apps (JavaScript is fine)
  • ❌ DOM manipulation (Wasm can’t access the DOM directly)
  • ❌ Small scripts (the overhead isn’t worth it)

Getting started with Rust + Wasm

Rust has the best WebAssembly tooling:

# Install the Wasm target
rustup target add wasm32-unknown-unknown

# Install wasm-pack (builds Rust β†’ Wasm with JS bindings)
cargo install wasm-pack

# Create a new project
cargo new --lib my-wasm-project
// src/lib.rs
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn fibonacci(n: u32) -> u32 {
    if n <= 1 { return n; }
    fibonacci(n - 1) + fibonacci(n - 2)
}
wasm-pack build --target web

Beyond the browser

WebAssembly also runs outside the browser:

  • Edge computing β€” Cloudflare Workers uses Wasm
  • Serverless β€” Wasm containers start in milliseconds (vs seconds for Docker)
  • Plugins β€” Envoy, Istio, and other tools use Wasm for extensibility