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?

@Reva@startrek.website
link
fedilink
English
71Y

As a hobbyist web dev:

  • I want to support niche browsers that might not support WASM such as Dillo or NetSurf.
  • Most of the resources out there are Javascript-only.
  • I don’t even use scripting most of the time in order to be accessible to text-only, old and minimalist browsers.

I can also imagine that people who are more professional than me in their development require existing JS frameworks, libraries, tutorials and whatever, and were taught in Javascript; there is no reason for them to change. There is also probably no real money in developing WASM applications commercially.

companero [he/him]
link
fedilink
English
31Y

Faster than JavaScript

JS is usually fast enough.

Has a smaller file size

It really depends. If you aren’t careful, your Wasm blob can end up ballooning in size. If you start pulling in libraries and doing things like parsing JSON, your binary can get big, quick.

Wasm adds an extra layer of complexity that needs to be justified. In most cases, it’s just not worth it.

Javascript is just really great. WASM is also great and really opens up some cool possibilities, but there is something inexplicably simple and approachable about Javascript. I think it will be very hard to topple it from its throne, even if WASM overcame it’s DOM issues.

deleted by creator

Mubelotix
link
fedilink
71Y

It’s only smaller for large apps

fiat_lux
link
fedilink
7
edit-2
1Y

How will we be making WASM-based UI accessible for people using screen readers, screen zoom applications, text to speech and voice input users, etc.?

The Web is hostile enough to people with disabilities, despite its intent, and developers are already unfamiliar with how to make proper semantic and accessible websites which use JS. Throwing the baby out with the bathwater by replacing everything with WASM in its current form seems about as good an idea as Google’s Web Environment Integrity proposal.

JS has little to do with accessibility. Most web accessibility comes from the Dom and aria attributes as well as semantic tags. You can do all of that with wasm too.

Are you asking about how it will work with wgpu based applications? This will work the same as it does on desktop applications. The program calls out to libraries that support talking to screen readers. I know rust the language with the best support for and ecosystem around wasm libraries like this already exist and ui frameworks like egui already have some support built in.

pelya
link
fedilink
231Y

I’ve ported games to web using WASM. You still need to interact with HTML DOM using JS, no way around it.

You use WASM when you either need raw CPU speed, or you have some C++ code that you don’t want to rewrite in JS.

If you just want to make a website, pure JS is better, unless you’re that kind of dev who prefers to render their own text strings pixel by pixel.

Nothing is stopping them. Have you seen Leptos? https://github.com/leptos-rs/leptos

@arthur@lemmy.zip
link
fedilink
English
11Y

JS have momentum, a lot of it.

@Nighed@sffa.community
link
fedilink
English
91Y

Unless it has improved since last time I used it then it’s awful to debug in the browser. I hate JavaScript, but would probably still use it for a new web project now.

If you use rust and structure your program correctly you can avoid debugging directly by building unit tests in language the verify behavior. Debugging tools are great and I look forward to better dx stories there (you can use chrome + DWARF to debug your native code) but strictly speaking it isn’t necessary most of the time.

Can you please elaborate on how, when using Rust, we can avoid needing to debug our JS code? I am very interested and hope that I didn’t misunderstand you.

IIRC a startup tried to exactly that… It’s wasn’t any faster and is actually harder to develop.

EDIT:

Sorry ignore these videos. I don’t remember which YouTube video it is. But more importantly Rust + WASM got really better than JS these days.

@PipedLinkBot@feddit.rocks
bot account
link
fedilink
English
21Y

Here is an alternative Piped link(s): https://piped.video/watch?v=461735zrjzY

Piped is a privacy-respecting open-source alternative frontend to YouTube.

I’m open-source, check me out at GitHub.

The video is essentially saying the exact opposite of what you are saying. It’s showing leptos to be much faster than react and I know primeagen doesn’t think rust is harder develop.

My bad. I can’t find the actually video but there exits a startup that shutdown because Rust/WASM performance wasn’t any better on top of that it’s was harder to develop with Rust. But as my edit to my previous comment shows things got better for Rust. It’s no longer the case.

@Mandy@beehaw.org
link
fedilink
English
51Y

So I gotta have to break out the xkcd comic again? Cause I will

λλλ
link
fedilink
21Y

Do it do it do it! 🤣

On the subject of dom manipulation from wasm I highly recommend this video https://youtu.be/4KtotxNAwME. It’s from leptos author, one of the more popular wasm framework. The TLDR is that modifying the dom isn’t the bottleneck for wasm.

@PipedLinkBot@feddit.rocks
bot account
link
fedilink
English
31Y

Here is an alternative Piped link(s): https://piped.video/4KtotxNAwME

Piped is a privacy-respecting open-source alternative frontend to YouTube.

I’m open-source, check me out at GitHub.

From my experience JS is primarily used to manipulate the DOM. I haven’t looked into it, but if you’re correct that WASM cannot manipulate the DOM then your question, to me, is tantamount to “Why aren’t people using forks to eat soup?”.

I would love a staticly-typed, compiled language to come along and replace JS. If anyone is aware of how I can write Rust in place of JS, please let me know. For now, I suffer/enjoy JS.

You can absolutely modify the dom, you just need to go through a thin js glue layer between the dom and wasm

Throwaway
link
fedilink
31Y

There’s Typescript, it’s as close as you can get.

For transpiled-to-JS languages: Elm, Purescript, Typescript

I personally use Elm. Really helps remove all the JS funny business, without really having to type it (mostly)

@nous@programming.dev
link
fedilink
English
6
edit-2
1Y

There are quite a few web frontend frameworks for rust now that are reasonably mature. Though you might still find a few rough edges they are usable for projects now.

All of these can work without you needing to write any JS code. Though there is JS glue code involved, it is generated and you don’t need to worry about it.

But the JS eco system is still quite large and hard to completely avoid.

I think the truth is that not only can’t WASM manipulate the DOM, but javascript was build to manipulate the DOM and has been moulded around this purpose. Secondly, if you want to use WASM from another programming language, that is just another language you need to learn on top of javascript, because we are not at a stage where we can replace javascript (because of the DOM). Fo most it’s more cost effective to just optimize their javascript code instead of adding another layer to the tech stack.

@nous@programming.dev
link
fedilink
English
31Y

I think the truth is that not only can’t WASM manipulate the DOM

Not directly no. But it can via JS (without the developer needing to ever touch JS code themselves via auto generated bindings). And this is simply a limitation of the current WASM implementations/standards. I believe there is work on going to get WASM more direct access to the DOM. But really this will just be an efficiency improvement over what is currently possible (which is already possibly to be as fast as pure JS frameworks).

Secondly, if you want to use WASM from another programming language, that is just another language you need to learn on top of javascript, because we are not at a stage where we can replace javascript (because of the DOM).

This is not quite true. Yes we cannot replace JS currently. But you don’t need to learn JS to develop using WASM - there is already enough tooling that can auto generate any JS code needed for you so developers never actually need to learn or touch JS if they don’t want to.

But existing developers that already know JS don’t have a huge reason to learn another language that only have a vastly less mature ecosystem. So the door is currently open for those that don’t enjoy or want to touch JS, but those people will at this point in time be working on other things rather then web apps. So there is not going to be a huge push for moving to a different language with WASM support any time soon. Not to mention that there is only minor benefits to existing applications that make a full rewrite to another language not worth the effort. So people wont be flocking over toward it, but not for the reasons you mentioned.

Sure, you can autogenerated js bindings, but as soon as you need to start debugging or optimizing you need to understand the js that was generated for you.

@nous@programming.dev
link
fedilink
English
21Y

I don’t think so. Having played around with wasm-bindgen in rust as well as other libraries the build on top of it I have never once needed to look at or understand the generated JS code. When you need to debug or optimise things the first thing to look at is the rust code. So as it stands today I do not think you need to know JS to write code for a web frontend - at least in isolation of anything else (ie teams, existing products etc).

You will likely need to learn JS at some point when writing stuff for the web - as the JS ecosystem is so vast for web development when compared to anything else. But WASMs JS bindings are not the point you will need to know it for.

Create a post

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 !webdev@programming.dev



  • 1 user online
  • 1 user / day
  • 1 user / week
  • 1 user / month
  • 1.11K users / 6 months
  • 1 subscriber
  • 1.21K Posts
  • 17.8K Comments
  • Modlog