WASM provides a compilation target for languages, enabling them to be compiled such as to be executable inside the browser.
Of course, it's lacking certain features currently - such as direct DOM access from WASM and initializing a binary without using JavaScript.
Ignoring that, the goal of a browser-compatible compile target is satisfied by JavaScript today. However, the output JavaScript will often be convoluted due to it being a high level language itself and often result in an output larger than the source code itself.
Assuming a world where DOM access existed inside wasm, would:
WebAssembly is a low-level assembly language that can run in any major browser. It's designed to be fast, much faster than JavaScript, in order to handle the modern use cases of the web that require higher performance.
JavaScript beats WebAssembly one more time. However, the difference is only 1.5 times at this run. We made the computation complicated and the difference got smaller. Maybe, we make the computation way complicated than we can see different results.
Regarding (1), WebAssembly modules are a size-efficient binary format. For that reason, it is more compact (i.e. smaller) than the equivalent logic represented by minified JavaScript.
Still, WebAssembly will allow developers to move intensive UI-blocking work outside of the browser. It will result in better performing web applications that run on newer and older hardware more smoothly. So, to answer the question (if the answer wasn't obvious enough), WebAssembly will not replace Javascript.
As you can imagine, this is not a question that can be answered definitely, however, I can give you a better understanding of the current situation and where things are going.
An app compiled to a WebAssembly module, will have the following component parts:
Looking at each in turn:
Regarding (1), WebAssembly modules are a size-efficient binary format. For that reason, it is more compact (i.e. smaller) than the equivalent logic represented by minified JavaScript.
Re:2, WebAssembly lacks common runtime features such as (heap) memory management and garbage collectors. For that reason, a runtime is often shipped alongside your application logic. In some cases (Rust) this runtime is quite lightweight, and in others (Blazor) it is very heavy. We will likely see the weight of these runtimes decreasing significantly over time due to new WebAssembly features (garbage collection, module caching) and better compilation techniques (ahead-of time compilation).
Re:3, as you acknowledged, WebAssembly lacks DOM access - in fact is lacks any form of I/O. At the moment your 'standard' WebAssembly tooling generates 'bindings' that aadd additional weight to your WebAssembly modules and some JavaScript 'glue' code. This will likely decrease over time as initiatives like the interface types proposal gains traction.
So to answer you questions, yes, I do think wasm modules will be more compact than their equivalents in future. I also think the runtimes will be delivered separately and cached, but more importantly this will significantly decrease in size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With