Single Page Applications using Rust (with WASM)
sheshbabu.com
sheshbabu.com
It's pretty young but solves a lot of ergonomic issues with UI in Rust. It's probably the closest you can get to React-level ergonomics (better in some ways) with Rust.
For my app (triviamaze.com), I ended up trying yew (which is referenced here) and then decided on seed (which is another rust WASM frontend framework which I preferred because it felt like the JSX syntax of yew did not play well with code completion, etc and felt weird to me inside Rust code).
However, for the followup web app (triviarex.com) I ended up using React for the frontend.
The big reason I did this was because React has a lot of tooling and compatibility. If I wanted a different CSS framework or to include one of the many available React components, it was easy. React also supports hot reloading, inbrowser debugging, etc.
What I did do, was use web sockets and Actix actors to manage all the state server side. Basically, all the React frontend code did was send messages to the server, and render the state the server sent back.
This to me felt like playing to the strengths of both languages. On the front-end, I got the flexibility and compatibility of Javascript. On the back end, I got to use all the Rust goodies such as pattern matching and strong typing for managing the state.
Is all the generated WASM worth it in terms of size and performance compared to using Typescript + a regular old front-end framework?
I can't remember where I read it but someone said reference based languages are kind of like using global variables everywhere.
It's possible that the compiler is turning all DOM operations into JS and the rest into WASM, but I don't think that's the case here.
It is good if you need to do maths or process videos, but doesn't give much advantage in processing JSON trees.
Also, I don't think it is necessary to make a SPA for a simple web store. Looks like overengineering to me. If you don't like that pages are reloading then use any library that automagically replaces the page content on link click. You can turn any "classic" server-side rendered site into something that feels like a SPA but without writing any JS code.
Regarding languages that are best for developers' performance, I guess it is Python? Are there languages that allow to solve typical web tasks using less tokens?
> Rust is very low-level language and doesn't have a garbage collector, so development with it will be slower than using JS.
Rust doesn’t have to be low level, and you rarely have to manage memory manually despite the lack of a garbage collector. That is actually one of the coolest features Rust provides: the borrow checker.
I’ve often found my development with it is orders of magnitudes faster than when I develop with javascript because of all the cool features Rust provides.
Since rust has a rich type system and generics, it is able to automatically generate all sorts of useful things at compile time. JSON boilerplate is only one example.
Also, the html! macro in the article allows for some nice syntactic sugar, presumably without giving up compile time type checking.
The SPA part feels like overkill, but they're demoing an SPA framework. There are many other rust web service frameworks.
This seems like a great reason to use Rust in the browser, or any other high performance statically typed language. We'd still expect substantial overhead from WASM for a while, but the idea that I can/could natively compile OpenCV to wasm and directly invoke it on the browser seems like a huge win.
First Contentful Paint 2.3s
Time to Interactive 2.3s
Largest Contentful Paint 3.9s
Cumulative Layout Shift 0.42
All numbers are coloured orange or red, so even Google isn't a fan.That said, 2*760ms of loading time comes from Google Fonts and Cloudflare's CDN for normalize.min.css. Were those hosted locally instead of on two useless CDNs, the times would probably almost less than a second, which, depressingly, is considered acceptable these days.
https://krausest.github.io/js-framework-benchmark/2022/table...
Having said that, I still wouldn't try to use Rust as a React replacement for other reasons. Maybe in a few years.