WebAssembly support now shipping in all major browsers
While Mozilla has been preparing to launch Firefox Quantum, its fastest browser yet, some notable developments have happened with WebAssembly, the binary file format (“wasm”) that works with JavaScript to run web applications at near-native speeds.
In the past weeks, both Apple and Microsoft have shipped new versions of Safari and Edge, respectively, that include support for WebAssembly. Since Mozilla Firefox and Google Chrome already support WebAssembly, that makes all four major browsers capable of running code compiled to the wasm format on the web.
“Google, Apple, and Microsoft had all committed to supporting WebAssembly in their browsers. To have that support in market today is a really exciting development,” said Luke Wagner, the Mozilla engineer who created WebAssembly’s precursor, asm.js, and spearheaded work on the WebAssembly specification.
For developers, broad client support means they can experiment with WebAssembly with assurance that most end users will be able to run super-fast wasm modules by default. Ubiquitous client support fueled the early success of asm.js. Since it is a pure subset of JavaScript, asm.js can run in any browser without modification. You can find asm.js on Facebook, where it powers popular games like Candy Crush Saga, Top Eleven, and Cloud Raiders.
A Growing Standard
What’s the big deal about WebAssembly? First, it’s on its way to becoming an industry standard. It’s a proven way to run large, complex applications on the web. And it gives web developers a number of options they’ve never had before. For instance, now you can:
- Take advantage of the compact wasm format to transmit files quickly over the wire and load them as JavaScript modules
- Get near-native performance without using a plug-in
- Write code that is both performant and safe, because it executes within the browser’s security sandbox
- Have a choice of languages besides JavaScript, using WebAssembly as a compiler target for C and C++, with additional language support to come.
How It’s Used Today
WebAssembly has caught the interest of a wide swath of technical folks, because it brings predictable performance to the web platform – something that’s been exceedingly difficult to achieve with JavaScript alone. Gaming companies were early adopters of WebAssembly and asm.js. Epic and Unity were first to put their industrial-strength game engines on the web without rewriting the C++ code bases in JavaScript.
Today, the use cases for WebAssembly and asm.js have grown beyond online gaming. As people experiment with the process of using the WebAssembly format and its cohort, the Emscripten compiler, they’re finding ways to move increasingly sophisticated applications to the web. Things like:
- Computer vision
- 3D mapping – Altus platform, Google Earth
- User-interface design
- Language detection
- Audio mixing
- Video codec support
- Digital signal processing
- Medical imaging
- Physical simulation
- Encryption
- Compression – zlib-asm, Brotli, lzma
- Computer algebra
“Asm.js and WebAssembly were really no-brainers for the gaming industry, because they had all this investment in massive C++ programs that they didn’t want to rewrite for the web,” Wagner said. “Now we’re seeing people using WebAssembly for all kinds of new projects. So there’s this real promise that we will someday be able to run most any application on the web and have it perform just as it would if it were running locally on your PC.”
Want to learn more about WebAssembly? Developers can find resources on MDN Web Docs and on the WebAssembly.org project site.
Interactive Tools
You can also try out WebAssembly Explorer, an online tool which allows you play around with a C/C++ compiler and understand how WebAssembly code is produced, delivered, and ultimately consumed by the browser. Another online tool, WebAssembly Fiddle, lets you write, share, and run WebAssembly code snippets in the browser. For an even deeper dive, you can inspect WebAssembly binaries to understand how WebAssembly code is encoded at a binary level.