04 Dec 2021

What is WebAssembly?

There always were only three technologies on the web - HTML, CSS and JavaScript. While JS may not be the best example of a well-designed language, it sure has a strong community and is pretty modern, apart from it being used everywhere. Although many optimizations were made to JavaScript engines, the introduction of the JIT compiler, is still nothing compared to the native speed of C or Rust. That's why, to bring this power to the Web, WebAssembly was born, a binary format that runs on near-native speeds. It is not meant to replace JavaScript but is an option for other languages to make a play in the browser world. WASM is great at doing intensive computations which JavaScript just wasn't made to be able to do. There are many things to WASM, you can give The Art of WebAssembly a try, it's a great book covering WebAssembly in great detail!

How to compile your code to WebAssembly?

C logo, C++ logo, Rust logo, AssemblyScript logo

Numerous tools help you compile your code into a WebAssembly binary. Here are some of them:

So as you can see many tools let you compile your project into a WebAssembly binary.

Let's try and compile AssemblyScript to WASM, this section requires that you know npm, TypeScript and JavaScript.

How to use WebAssembly?

Javascript and WebAssembly logo

Considering you already do have a WASM binary ready, it's time to load it on your website using JavaScript. We'll be using plain HTML and JS for this.

Of course, that's a very simple example just to get you started, there are way more complex things you can do using WASM! To get o more advanced stuff, we recommend you read a fantastic book WebAssembly: The Definitive Guide

Some examples of WASM usage:

Current WASM drawbacks:

As you can see, this section is called Current WASM drawbacks, as new proposals and functionalities are being added, you can track WebAssembly on GitHub.

By Maciej Oliwa on 04 Dec 2021

rating star rating star rating star rating star rating star
Rating: 5.0 - 1 reviews

If you found this helpful, click on the Google Star, Like it on Facebook or follow us on Twitter and Instagram