this post was submitted on 07 Aug 2023
86 points (98.9% liked)

Programming

16975 readers
1288 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

I've been wondering about this for a while and haven't really found a great answer for it. From what I understand, WASM is:

  • Faster than JavaScript

  • Has a smaller file size

  • Can be compiled to from pretty much any programming language

  • Can be used outside of the browser easier thanks to WASI

So why aren't most websites starting to try replacing (most) JS with WASM now that it's supported by every major browser? The most compelling argument I heard is that WASM can't manipulate the DOM and a lot of people don't want to deal with gluing JS code to it, but aside from that, is there something I'm missing?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 16 points 1 year ago* (last edited 1 year ago) (1 children)

The truth is that JS is currently "good enough" and all the best (adopted) web frameworks are either server or JS based.

I believe the chunking of script files is currently a bit more natural as well.

WebAssembly is the best choice for certain kinds of apps but most web apps are good enough with JS. If communities pour a lot of polish into WASM frameworks you may start to see wider adoption. Diversity is good, but it does need to be asked why WASM + DOM is objectively better than JS + DOM. It complicates the ecosystem a bit because you might fracture it for no good reason. Should there be Rust, Python, and JS DOM rendering frameworks? Is there a benefit?

If you have a more traditionally native app you want to port, that's different. That's a great fit for WASM. Personally I see it becoming more popular when it's a good replacement for desktop technology and the DOM isn't used at all (go straight to GPU). I'm a huge fan of WASM, but I also write a lot of web apps and don't see a super convincing reason to adopt WASM to effectively make the exact same thing. As-is, it's great for augmenting an app though.

Wait for garbage collection and sockets and you might see the paradigm start to shift.

[–] [email protected] 3 points 1 year ago (1 children)

This is it.

WebAssembly AFAICT is all about making existing code runnable in a JavaScript environment. JavaScript isn't great itself, but Chrome provides pretty amazing tooling, so it's good enough.

Add to that: if you want to write WASM in a strongly typed language, you need support libraries that define all of the browser primitives. If you're an accomplished web developer, it's more effective to stay in js.

[–] [email protected] 2 points 1 year ago

WebAssembly AFAICT is all about making existing code runnable in a JavaScript environment.

I would not say that. It is one aspect of web asm, but not the only or even main reason. There are far more frameworks and tooling out there designed for writing new stuff in it rather than getting existing stuff to run.

if you want to write WASM in a strongly typed language, you need support libraries that define all of the browser primitives.

These already exist for some languages - notably rust (but not exclusively). You can now write a web app fully in rust and have it preform on par with popular JS frameworks. There is JS involved in this - but it can all be generated so developers never need to actually touch it.

If you’re an accomplished web developer, it’s more effective to stay in js.

This is true, and the bigger reason why wasm is not as popular. If you already know a JS web framework there is little point in learning a whole new language as JS is good enough for most applications. And a whole new language and tooling is a large investment. But it does mean that people in other eco systems or that don't really like JS are now able to write webapps in other languages (which by the very nature are going to be a fraction of web devs as these people will likely have avoided it where they can). Other eco systems are also a lot less mature than JSs eco system for web development.