WebAssembly

Draft
This page is not complete.

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

WebAssembly is a new type of code that can be run in modern web browsers — it is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages such as C/C++ with a compilation target so that they can run on the web. It is also designed to run alongside JavaScript, allowing both to work together.

In a nutshell

WebAssembly has huge implications for the web platform — it will provide a way to run code written in multiple languages on the web at near native speed, with client apps running on the web that previously couldn’t have done so.

WebAssembly is designed to complement and run alongside JavaScript — using the WebAssembly JavaScript APIs, you can load WebAssembly modules into a JavaScript app and share functionality between the two. This allows you to take advantage of WebAssembly's performance and power and JavaScript's expressiveness and flexibility in the same apps, even if you don't know how to write WebAssembly code.

And what's even better is that it is being developed as a web standard via the W3C WebAssembly Community Group with active participation from all major browser vendors.

Guides and tutorials

WebAssembly concepts
Get started by reading the high-level concepts behind webAssembly — what it is, why it is so useful, how it fits into the web platform (and beyond), and how you would start to make use of it.
Compiling from C/C++ to WebAssembly
When you’ve written a code module in a language like C/C++, you can then compile it into .wasm using a tool like Emscripten. Let’s look at how it works.
Using the WebAssembly JavaScript API
Now you've compied your own wasm module, you'll want to use it somewhere. The most obvious option is to use it inside a web app — in this article we show you how to do that, including loading a module and passing functions to and from it using imports and exports, how to use WebAssembly memory and tables, and more.
Understanding WebAssembly text format
To enable WebAssembly to be read and edited by humans, it has textual representation of the wasm binary format. This is an intermediate form designed to exposed in text editors, browser developer tools, etc. This article explains how that text format works, in terms of the raw syntax, and how it is related to the underlying bytecode it represents — and the wrapper objects representing wasm in JavaScript.
Converting WebAssembly text format to wasm
This article provides a guide on how to convert WebAssembly text format to a wasm module.
Fetching WebAssembly bytecode
To use wasm in JavaScript, you first need to pull your module into memory before compilation/instantiation. Modules will initially be captured as typed arrays, e.g. via XMLHttpRequest or Fetch, but more options will likely develop in the future.
Caching compiled WebAssembly modules
Caching is useful for improving the performance of an app — we can store compiled WebAssembly modules on the client so they don't have to be downloaded and compiled every time. This article explains the best practices around this (e.g. using IndexedDB).
Exported WebAssembly functions
Exported WebAssembly functions are how WebAssembly functions are represented in JavaScript. This article describes what they are in a little more detail.

API reference

WebAssembly
This object represents the WebAssembly environment in JavaScript, and acts as the namespace for all WebAssembly related functionality.
WebAssembly.Module()
The WebAssembly.Module() constructor creates a Module object instance, which represents a compiled wasm module. This allows you to access information such as what imports and exports are available on the module.
WebAssembly.Instance()
The WebAssembly.Instance() constructor creates an Instance object instance, which represents an instance of a wasm module. This allows you to access the functions exported from a module and use their results in JavaScript.
WebAssembly.Memory()
The WebAssembly.Memory() constructor creates a Memory object instance, which represents a WebAssembly Memory, allowing you to get and set values inside the memory, make it larger, etc.
WebAssembly.Table()
The WebAssembly.Table() constructor creates a Table object instance, which represents a WebAssembly Table — this enables you to store and retrieve function references.
WebAssembly.CompileError()
Creates a new WebAssembly CompileError object instance.
WebAssembly.LinkError()
Creates a new WebAssembly LinkError object instance.
WebAssembly.RuntimeError()
Creates a new WebAssembly RuntimeError object instance.

Examples

Specifications

Specification Status Comment
Web Assembly JavaScript API Draft Initial draft definition of the JavaScript API.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support No support[1] No support No support[2] No support No support[1] No support
Feature Android Android Webview Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support No support[1] No support No support[2] No support No support No support No support[1]

[1] Experimental support can be enabled in Chrome 51+ and Opera 38+ by going to chrome://flags and enabling the Experimental WebAssembly flag.

[2] Experimental support can be enabled in Firefox 47+ by enabling the javascript.options.wasm flag in about:config.

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, lukewagner
 Last updated by: chrisdavidmills,