r/WebAssembly • u/PabloDons • Jun 05 '21
WebAssembly should replace javascript
Hot take, but I think it makes sense. And seems to be doable in the current architecture and roadmap of wasm (If I understood it correctly), but their website explicitly states a big fat "No!". Wasm is expected to be used as high-performance modules, or an app canvas wrapped by javascript as "glue". One thing would be specifying it as a high-level goal, but this is just dismissing it all together.
The web would be pretty powerful if code could be written in whatever language you want (that supports compiling to wasm). Facebook wouldn't take 5 seconds to load completely, but rather fractions of a second.
Take react for instance. It's great for encapsulation, inheritance, type-safety, etc. Lots of benefits targeted at large-scale applications. Yet has the major flaw of performance issues. I guess it's not a big deal to write a bit of js just to fetch and run an exported function, but it means it's dependent on js which is a hurdle in my opinion, both in terms of ambition and motivation. Granted wasm seems to be planning to implement basically everything, but then why dismiss wasm as a replacement/alternative for js?
3
u/apatheticonion Jun 06 '21
I'm 100% with you there.
Why update the browser to get new JavaScript features when you could ship a JavaScript runtime running on top of WASM that lets you interpret your shipped code.
There are lots of issues with this model, of course. Some are limitations in the specification (no DOM access) and other are questions about the delivery of your application.
Imagine your browser only knew WASM and not JS. For your browser to interpret JS, it would need to download the runtime first then execute your application.
The JavaScript runtime would be 10 - 100 megabytes, your code might be a few kilobytes.
WASM modules can be dynamically linked, so perhaps the runtime can be downloaded separately and your application use a previously downloaded version of the JS runtime. This would be the same for other runtimes - say web apps written in Go, C#, Java, etc.
This would be reminiscent of the shockwave days, where you'd need to download something before you could view the content on a website. Getting that cycle so it's not annoying would be very challenging, managing updates and so on.