Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a WebAssembly (Wasm) module?

Was reading the MDN docs regarding Wasm. They used the term WASM module quite a few times. Their definition was the following:

A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser and can be efficiently shared with Workers, and instantiated multiple times. To instantiate the module, call the secondary overload of WebAssembly.instantiate().

I couldn't quite understand the meaning of this. Is a web assembly module simply a Wasm file or is it something else?

like image 230
Willem van der Veen Avatar asked Mar 06 '23 06:03

Willem van der Veen


1 Answers

What is Web Assembly?

Web Assembly(Wasm) is a way of taking code written in programming languages other than JavaScript and running that code in the browser.

It is generated by the compiler with a binary format which allows us to execute any language code on the browser

How does it work?

Despite its name, WebAssembly is not quite an assembly language because it’s not meant for any specific machine. It’s for the browsers, and when you’re delivering code to be executed in the browser, you don’t know what kinds of machines will your code be running on.

What WebAssembly enables you to do is to take things like C, C++ or Rust code and compile it into what is called a WebAssembly module. You can load that into your web application and call it from JavaScript.

Wasm programs are deployed in two stages.

  1. Wasm module is generated from the source code (any language of your choice other than JavaScript)
  2. Once the Wasm module is built, it can be run anywhere with a few lines of JavaScript glue:

It’s not a replacement for JavaScript, it works alongside JavaScript.

Here is a great article to go more in details.

like image 126
pk_code Avatar answered Mar 20 '23 06:03

pk_code