Oleg Blokhin - Getty Images

Tip

Why WebAssembly? Top 11 Wasm benefits

Latency and lag time plague web applications that run JavaScript in the browser. Here are 11 reasons why WebAssembly has the potential to completely change that.

When the World Wide Web Consortium designed WebAssembly, the primary goal was to address the shortcomings of running client-side JavaScript in a web browser.

However, as developers begin to adopt and embrace the spec, they reveal several advantages to the use of WebAssembly (Wasm), both on the client side and the server side.

WebAssembly benefits

Overall, here are 11 benefits of WebAssembly today:

  1. WebAssembly is a World Wide Web Consortium (W3C) standard.
  2. WebAssembly supports multiple languages.
  3. WebAssembly is compact.
  4. WebAssembly is fast.
  5. WebAssembly is universally supported.
  6. WebAssembly is safe and secure.
  7. WebAssembly is hardware-independent.
  8. WebAssembly can run inside Docker.
  9. WebAssembly can be written in a low-level language.
  10. WebAssembly is a proven technology.
  11. WebAssembly is transparent to the client.

WebAssembly is a W3C standard

WebAssembly is the fourth official language of the web. HTML, CSS and JavaScript are the other three.

WebAssembly is backed by the W3C, a public, international organization dedicated to open standards. Led by Tim Berners-Lee, the inventor of the web, the W3C is vendor-independent and thus can pursue open standards that provide for the best interests of the community.

Put simply, the W3C decides which technologies are the official languages of the web. The W3C's nod to WebAssembly bestows credibility and confidence in the technology.

WebAssembly supports multiple programming languages

WebAssembly is language-independent. Developers can write Wasm apps in Java, Python, Rust, Golang or C++ so long as they have a compiler to convert the source code into WebAssembly-compatible binaries.

This means developers of all stripes, not just ones acquainted with JavaScript, can write complex logic that targets the web browser.

They dynamically typed nature of Python, and the built-in garbage collection routines of Java, make those languages more complex to port to WebAssembly than C++ or Rust, but progress continues on those fronts.

Chart showing WebAssembly/Wasm components and interactions.
WebAssembly accommodates a wide range of programming languages, OSes, hardware components, applications and frameworks, so developers can build platform- and device-agnostic apps without refactoring.

WebAssembly is compact

A Web browser downloads JavaScript as plain text.

An uncompressed JavaScript file can be 100 times larger than an equivalent WebAssembly file. Even with compressed JavaScript, a WebAssembly file is one-tenth the size of the equivalent piece of JavaScript code.

The benefit is that smaller WebAssembly apps download faster, which reduces the time for a webpage to become interactive.

WebAssembly is fast

Compiled WebAssembly code runs much faster than dynamically loaded JavaScript files.

Performance tricks such as just-in-time (JIT) or ahead-of-time (AOT) compilation can be used to achieve near-native performance of WebAssembly code.

Near-native performance just isn't possible with browser-based JavaScript.

WebAssembly is universally supported

WebAssembly is a W3C standard, but that doesn't mean much if the standard lacks widespread support.

Fortunately, WebAssembly is fully supported by the web browser community. Chrome, Firefox, Edge and Safari all execute WebAssembly files.

WebAssembly is secure

The virtual machine validates WebAssembly code before it runs, and executes it inside a memory-safe sandbox. The embedded environment limits access to local resources such as the file system or network ports.

That means WebAssembly code that is downloaded from the internet and runs in the browser is highly restricted with regard to the hardware and software resources it can access. However, code deployed to a Docker container can be given full network and file system access if needed.

WebAssembly is hardware-independent

At both build-time and runtime, WebAssembly is hardware-independent.

Programmers can build deployable WebAssembly packages regardless of whether they develop on Windows, MacOS or Linux. Furthermore, the builds they create can run on any target operating system so long as the WebAssembly virtual machine is supported.

WebAssembly can run inside a container

WebAssembly is a W3C standard, but that doesn't mean it's limited to the web browser.

The WebAssembly virtual instruction set architecture can embed itself into a variety of environments, including a Docker container.

That means developers can use their language of choice to create both browser-based web applications and server-side microservices. A Rust developer, for example, can write a microservice for the server and logic for the web browser, and not worry about JavaScript's limitations, such as security.

WebAssembly can be written in WAT

Most WebAssembly apps will be written in a high-level language such as C or Java. However, it's possible to write programs in the WebAssembly Text (WAT) format.

Unlike languages such as Rust or Java that compile code into a set of instructions, WAT allows developers to edit the instructions themselves. This provides greater control over execution, performance, timing and the instructions contained in the binary execution file generated for WebAssembly.

WebAssembly is a proven technology

Not only do all the major browsers support WebAssembly, but impressive and complex examples of WebAssembly applications have been built, deployed and run successfully inside the web browser.

Several popular apps use WebAssembly to run in a browser: Adobe Acrobat and Photoshop, and AutoDesk AutoCAD. Two other examples are the ports of the Unity and Unreal Engines to WebAssembly.

The success of these projects proves that WebAssembly is powerful enough to handle the extreme needs of graphics processing and rendering within a web browser.

WebAssembly is transparent to the client

WebAssembly officially became a W3C standard in 2019. Still, most web users, and a large number of web developers, have never heard of it.

That's not surprising. The use of WebAssembly is transparent to the user, and within a web application, Wasm code is accessed through standard APIs. If a developer wasn't looking for it, they wouldn't know it was there.

That transparency is one of the great things about WebAssembly. Code written in WebAssembly does its job and doesn't significantly impede on other parts of the software development stack. WebAssembly is without a doubt the least disruptive of all the disruptive technologies to come about in the past 10 years.

Dig Deeper on Front-end, back-end and middle-tier frameworks