DEV Community

Cover image for Web Assembly
Akram Saouri
Akram Saouri

Posted on

Web Assembly

Web Assembly, the what, the why and the how

The what

Web assembly also called Wasm is an efficient, low level byte code for the web, the efficient part means that it’s not only fast to deliver to the client browser but also fast to execute, it’s characterised by being a safe and a portable language meaning that you won’t have to deal with memory overflows and issues like that and the generated machine code can be executed on any platform and adapts to its architecture.

The why

W3C created Wasm for two major reasons, the first one as a complementary solution to JavaScript especially for applications with heavily CPU/GPU computations (think games, encryption, image or video optimisation and editing etc..), and the second one is to enable developers to write their web apps in other languages.

The how

Wasm is defined as a compilation target meaning that in a normal scenario you would write your program in some other languages (currently supporting C/C++ and Rust) and then compile it to a web assembly executable file.
The generated binary file can be injected to your web application and the browser parsing the file will skip all the steps usually run when parsing JS files and go straight to generating the machine code for the platform you’re using, and this is happening because Wasm is already optimised and has static types informations.

Getting started

To play around with Wasm, I recommend https://webassembly.studio/ which is an awesome web editor allowing devs to experiment with Wasm and write web assembly based projects.
There is also https://mbebenita.github.io/WasmExplorer/ which is basically a tool used to translate C/C++ code to Wasm binary code and even see the linear assembly byte-code generated by the browser (this is basically the human readable intermediary representation for the machine code)

Top comments (3)

Collapse
 
gpapadak profile image
Giorgos Papadakis

Many peaple miss that, still believing that wasm is just some fancy web idea for heavy apps hahahaha.
There is an implementation a compiler and many more in a package called blazor. Just take a look is a full replacement for javascript and that its meant to be from the beginning.

Collapse
 
avikaminetzky profile image
Avi Kaminetzky
Collapse
 
rodneyringler profile image
rodney ringler

In c#/.net there is the blazor project that has ported the mono engine to webassembly and they have working c# apps in the browser. They even have a spa written in c#.