WebAssembly (WASM): fast code in the browser
In short: WebAssembly is a compact binary format that browsers run at nearly machine-code speed. Languages like C, C++, Rust or Go can be compiled to it, so they run on the page next to JavaScript.
Why it exists
JavaScript is made for interfaces but is too slow for heavy computing (image editing, games, compression, emulators). WASM brings a precompiled, quickly loadable format for that.
How it works
- Source code (for example Rust) is turned into a
.wasmfile by a Compiler. - The page loads the file and creates a module. The browser validates it and translates it to machine code.
- JavaScript calls the module’s functions and exchanges numbers or memory regions.
WASM has no direct access to the page, files or network. Everything it may do must be explicitly handed to it by JavaScript.
Security
A module runs in a Sandbox with its own limited memory. It cannot freely break out of the browser. Still, load only modules from trusted sources, and a content security policy can specifically allow or forbid compiling WASM.
Examples
Emzett runs Python in the browser (Pyodide), a database in the browser (sql.js) and a small Linux emulator as WASM. Nothing needs to run on the server for that.
Limits
WASM doesn’t replace JavaScript: interface, events and page building stay there. The gain shows with compute-heavy tasks; for a form it brings nothing.