Hi rustaecans!
Im building a blog for my project 8080_msg, and I'm currently building the backend in rust, but I was wondering could/should I use rust for the front-end via WASM or should I just use "standard" html/css/javascript?
Hi rustaecans!
Im building a blog for my project 8080_msg, and I'm currently building the backend in rust, but I was wondering could/should I use rust for the front-end via WASM or should I just use "standard" html/css/javascript?
You definitely could use it but IMO it makes sense to use rust in front-end only if you have some heavy computations or just for fun (if you'd like to try it). If you just need the job to be done, standard way gonna be way easier.
I think I'll build the front-end in rust to increase my rust experience, are there any official resources about rust and WASM?
a blog is pretty static on the client, so you could get away with "standard" html/css and no js, rendering everything server-side with e.g. askama templates
First of all, I'm not a WASM expert so feel free to correct me, but AFAIK WASM is not "front-end in non-js languages". WASM - is a way to run binary code inside a browser. Those code can be called from JS. It's not a replacement for HTML/CSS/JS or whatever else, it's just addition to them. Although there are ways to interact with DOM (Document Object Model - basically what you usually describe with HTML) from the WASM code but it's not direct interaction, it still gonna use JS calls.
Anyway, here's the official book about WASM and Rust. Also if you'd like to specifically "write front-end in Rust instead of html/css/js or any js framework over them", there is Yew framework which allows to do something similar in Rust. I'm not sure about how it works under the hood but I encourage to look around the examples and then decide if it's worth it. IMO it looks like a thing to play with but not something you'd like to do to solve real problems.
You can get away with just html and css, pre rendered whenever the blog source changes. You should only be serving static files. Of course you can also have js if needed, for example, to syntax highlight code blocks rather than doing that during pre rendering, or for interactive examples, etc. In any case, you should minify the html and css, and if the css is page specific, embed it directly inside <head> rather than linking to a file. There is absolutely no need to use a framework, yet alone one that requires a network request to load a webassembly module to insert static text into the dom.
You can build the frontend in Rust. That’s what the crate leptos is for.
If I recall correctly, every call to a browser API costs more than the equivalent in JavaScript. While base performance is faster in wasm, any short computations will be faster in JS.
Still, if you want to write Rust on the frontend, do it!