Web Development

WebAssembly Explained: What It Is and When to Use It

December 3, 2026 · 11 min read

WebAssembly Explained: What It Is and When to Use It

WebAssembly, often shortened to Wasm, lets websites and apps run code written in languages such as C, C++, Rust and Go at close to native speed, safely, in every modern browser. It is the reason design tools, video editors, games and even Python notebooks can now run in a browser tab without plugins. It also runs outside the browser, on servers, at the edge and inside other applications as a secure plugin format.

This guide explains what WebAssembly is, how it works, what changed with WebAssembly 3.0 and WASI 0.3, how it compares with JavaScript, and when it is worth using. You will also see a tiny module written by hand and run in Node.js, a React hook for loading Wasm and a short Rust example.

What Is WebAssembly?

WebAssembly is a compact binary instruction format for a virtual machine. Instead of writing it directly, you usually compile code from another language into a .wasm file, which browsers download, check and compile into fast machine code. It became an official W3C standard in 2019 and is supported by Chrome, Edge, Firefox and Safari. The WebAssembly project site and MDN's WebAssembly docs are the best starting points.

Four properties explain why it matters:

  • Fast: code arrives pre-compiled to a low-level format, so it starts quickly and runs with predictable performance.
  • Safe: modules run in a sandbox with their own memory and can only reach the outside world through functions the host gives them.
  • Portable: the same module runs on any operating system and processor that has a Wasm runtime.
  • Language-neutral: C, C++, Rust, Go, C#, Kotlin, Zig, AssemblyScript and others can all compile to it.

How WebAssembly Works

A Wasm module declares function types, functions, memory and exports. JavaScript loads the module, passes in any functions it needs, such as logging or network access, and calls the functions the module exports. To show how small and concrete this is, here is a complete module written byte by byte and run with nothing but Node.js:

// tiny-wasm.mjs - an 81-byte WebAssembly module written by hand, compiled and run by Node (or any browser)
const bytes = new Uint8Array([
  0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, // "\0asm" magic number, version 1
  // Type section: two function signatures
  0x01, 0x0c, 0x02,
  0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f,             // type 0: (i32, i32) -> i32
  0x60, 0x01, 0x7e, 0x01, 0x7e,                   // type 1: (i64) -> i64
  // Function section: function 0 uses type 0, function 1 uses type 1
  0x03, 0x03, 0x02, 0x00, 0x01,
  // Export section: "add" = function 0, "factorial" = function 1
  0x07, 0x13, 0x02,
  0x03, 0x61, 0x64, 0x64, 0x00, 0x00,
  0x09, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x69, 0x61, 0x6c, 0x00, 0x01,
  // Code section: the two function bodies
  0x0a, 0x1f, 0x02,
  0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b, // add: local.get 0, local.get 1, i32.add
  0x15, 0x00,                                      // factorial (recursive):
  0x20, 0x00, 0x50,                                //   if n == 0
  0x04, 0x7e, 0x42, 0x01,                          //     then 1
  0x05, 0x20, 0x00,                                //     else n *
  0x20, 0x00, 0x42, 0x01, 0x7d, 0x10, 0x01,        //       factorial(n - 1)
  0x7e, 0x0b, 0x0b,                                //   i64.mul, end if, end function
]);

console.log("Valid module:", WebAssembly.validate(bytes), `(${bytes.length} bytes)`);
const { instance } = await WebAssembly.instantiate(bytes);
const { add, factorial } = instance.exports;
console.log("add(2, 40) =", add(2, 40));
console.log("factorial(20n) =", factorial(20n)); // i64 values cross into JavaScript as BigInt
console.log("Exports:", WebAssembly.Module.exports(new WebAssembly.Module(bytes)).map((e) => e.name).join(", "));

It prints that the 81-byte module is valid, that add(2, 40) returns 42, and that factorial(20n) returns 2432902008176640000n. The second function uses 64-bit integers, which arrive in JavaScript as BigInt values. Nobody writes Wasm bytes by hand in real projects. The readable text format, called WAT, expresses the same module like this:

;; tiny.wat - the same module in WebAssembly's text format (compiles to the identical 81 bytes)
(module
  (func (export "add") (param i32 i32) (result i32)
    local.get 0
    local.get 1
    i32.add)
  (func $factorial (export "factorial") (param i64) (result i64)
    local.get 0
    i64.eqz
    if (result i64)
      i64.const 1
    else
      local.get 0
      local.get 0
      i64.const 1
      i64.sub
      call $factorial
      i64.mul
    end))

Tools such as wabt convert WAT to the binary format and back, which is handy for learning and debugging. In practice, a compiler such as Rust's or Emscripten for C and C++ produces the binary for you.

What Is New: WebAssembly 3.0 and WASI 0.3

WebAssembly has grown well beyond its first version. WebAssembly 3.0, completed in September 2025, was the biggest update yet. Its main additions:

  • Garbage collection: languages such as Java, Kotlin, Dart and OCaml can compile to Wasm efficiently, using the browser's garbage collector instead of shipping their own.
  • 64-bit memory: modules can address far more than 4 GB, which matters for large datasets and AI models.
  • Multiple memories, exception handling, tail calls and typed references: features that make compilers' output faster and smaller.

Outside the browser, the WebAssembly System Interface (WASI) defines standard ways for modules to use files, networking and clocks. The Bytecode Alliance released WASI 0.3 in June 2026 with native asynchronous support in the Component Model, a major step for server-side Wasm. In browsers, JavaScript Promise Integration, which lets synchronous Wasm code call asynchronous web APIs, is one of the focus areas of Interop 2026, the cross-browser effort to make features work consistently.

WebAssembly vs JavaScript

FactorWebAssemblyJavaScript
PerformanceFast and predictable for heavy computationVery fast for typical app code thanks to JIT compilers
Access to the pageNo direct DOM access; calls go through JavaScriptFull access to the DOM and web APIs
LanguagesC, C++, Rust, Go, C#, Kotlin and moreJavaScript and TypeScript
Download sizeCompact binary, but runtimes for some languages add weightText, compressed well by servers
DebuggingImproving, with source maps and DWARF supportMature tools in every browser
Best forCompute-heavy work and reusing existing native codeUser interfaces and application logic

WebAssembly does not replace JavaScript. The two work together: JavaScript runs the interface, and Wasm handles the heavy lifting. If you are choosing a language for everyday web work, start with our guide to TypeScript vs JavaScript.

When to Use WebAssembly

  • Media processing: image editing, video encoding and audio effects in the browser.
  • Design and engineering tools: Figma rebuilt its editor engine on WebAssembly and reported that it cut load time by three times; CAD and 3D tools follow the same pattern.
  • Games: engines such as Unity and Godot can export to the web through Wasm.
  • Porting existing code: mature C, C++ or Rust libraries, such as SQLite or FFmpeg, can run in the browser without rewriting them in JavaScript.
  • AI in the browser: inference libraries use Wasm, often alongside WebGPU, to run models locally for privacy and offline use. Our guides to on-device AI and running LLMs locally cover this trend.
  • Python and data science in the browser: Pyodide compiles Python and scientific libraries to Wasm.
  • Secure plugins and edge code: platforms run untrusted or third-party code in Wasm sandboxes, and edge services such as Cloudflare Workers run Wasm close to users.

When Not to Use It

  • Typical business apps, dashboards and forms, where JavaScript is already fast enough.
  • Code that mostly updates the page, because every DOM change has to cross back into JavaScript.
  • Small, frequent function calls where the cost of passing data between JavaScript and Wasm outweighs any speed gain.
  • Teams without experience in a compiled language, unless a ready-made Wasm library does the job.

Measure first. Profile the slow part of your app, try an optimised JavaScript version, and move to Wasm only when it clearly wins.

Using WebAssembly in a React App

From React's point of view, a Wasm module is just an asynchronous resource. Load it once, keep its exports in state and call them like any other function. This hook uses streaming compilation, so the browser compiles the module while it downloads:

// useWasm.js - load a .wasm file once in a React component and expose its exports
import { useEffect, useState } from "react";

export function useWasm(url, imports = {}) {
  const [exports, setExports] = useState(null);
  const [error, setError] = useState(null);

  useEffect(() => {
    let cancelled = false;
    // Streaming compilation starts while the file is still downloading (serve it as application/wasm).
    WebAssembly.instantiateStreaming(fetch(url), imports)
      .then(({ instance }) => { if (!cancelled) setExports(instance.exports); })
      .catch((err) => { if (!cancelled) setError(err); });
    return () => { cancelled = true; };
  }, [url]);

  return { exports, error, loading: !exports && !error };
}

Serve .wasm files with the application/wasm content type and long cache lifetimes, load them only on the pages that need them, and run long computations in a Web Worker so the interface stays responsive. Many libraries now ship their Wasm inside an npm package, so you import a normal JavaScript API and never touch the .wasm file yourself. If you prefer Vue or Angular, the same approach works there; see our comparison of React, Vue and Angular.

To write your own module, Rust has the most polished tooling. With wasm-bindgen, exposing a function to JavaScript takes one attribute:

// src/lib.rs - a Rust function exposed to JavaScript; build with: wasm-pack build --target web
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn word_count(text: &str) -> usize {
    text.split_whitespace().count()
}

wasm-pack compiles this into a .wasm file plus a JavaScript wrapper, so your React code can import word_count and call it with an ordinary string. TypeScript developers can try AssemblyScript, a TypeScript-like language that compiles straight to Wasm.

Tips for Fast, Small WebAssembly

  • Optimise the build: compile in release mode and run wasm-opt from the Binaryen toolkit to shrink and speed up the output.
  • Compress it: serve .wasm files with Brotli or gzip, which often cut their size dramatically.
  • Avoid copying data: share large buffers through the module's memory instead of converting values back and forth.
  • Use SIMD and threads where they help: vector instructions are widely supported, and threads need cross-origin isolation headers so the browser allows shared memory.
  • Cache compiled modules: long cache lifetimes let browsers reuse their compiled code on later visits.

WebAssembly Beyond the Browser

Server-side WebAssembly is growing because modules start in milliseconds, use little memory and run in a strong sandbox. Runtimes such as Wasmtime run WASI modules on servers, and Node.js, Deno and Bun can all load Wasm; our comparison of Node.js, Bun and Deno looks at those runtimes in detail. Common uses include plugin systems for databases and proxies, serverless functions with very fast cold starts, and running the same business logic on server, browser and device. For apps that must also work offline on phones, Wasm pairs well with progressive web apps.

How to Get Started

  1. Find an existing Wasm library first. Many problems, such as image processing, PDF handling and compression, already have one.
  2. Pick a language for your own modules: Rust with wasm-bindgen, C or C++ with Emscripten, AssemblyScript for TypeScript developers, Go or TinyGo, or C# with Blazor.
  3. Start small: move one hot function into Wasm and measure the difference.
  4. Plan the boundary: pass large chunks of data rarely rather than small pieces often.
  5. Test in every browser you support, and keep a JavaScript fallback if a feature is new.

If you are deciding which languages to invest in, our guide to the best programming languages to learn covers Rust, Go and C# alongside JavaScript.

Frequently Asked Questions

Is WebAssembly faster than JavaScript?

For compute-heavy work such as image processing, physics or compression, usually yes, and its performance is more predictable. For typical interface code, modern JavaScript engines are fast enough that Wasm offers little benefit.

Will WebAssembly replace JavaScript?

No. WebAssembly cannot access the page directly and is designed to work alongside JavaScript. Most apps that use Wasm keep their interface and logic in JavaScript or TypeScript.

Which languages compile to WebAssembly?

Rust, C, C++, Go, C#, Kotlin, Zig, Swift, Dart and AssemblyScript are among the most common. Python and other interpreted languages run through Wasm builds of their interpreters, such as Pyodide.

Is WebAssembly secure?

Wasm runs in a sandbox with its own memory and can only use functions the host provides, which makes it a strong isolation layer. Code inside a module can still have bugs, so normal secure coding practices apply.

Can WebAssembly be used on the server?

Yes. Runtimes such as Wasmtime, and JavaScript runtimes such as Node.js, run Wasm on servers. WASI gives modules standard access to files, networking and clocks, and edge platforms run Wasm close to users.

Does WebAssembly work in all browsers?

Yes. All major browsers support the core standard. Newer features roll out at different speeds, so check support for anything recent, such as garbage collection or JavaScript Promise Integration.

Bring High-Performance Features to the Web

We build web apps that use WebAssembly where it makes a real difference, from media processing and in-browser AI to porting native libraries to the web. Contact our team to discuss your project.

Want this built for you?

Our team offers Website Deploy On Vercel — get a free quote.

View Services