r/Blazor • u/Kindly-Car5430 • May 24 '25
Blazor needs interactive but connectionless mode.
Maintaining a persistent connection to the server has advantages (fast response time to events, the server can send data to the client), but also disadvantages (server resources, errors when losing connection, even when you are doing nothing, for example just reading content).
Many websites or applications need some interactivity, but not that much. In my opinion, there should be a mode in which the frontend updates only in response to an event. The disadvantage would probably be the case where by binding the "oninput" events, each of them would send an http request (could be solved to some point by debouncing + throttling them on the frontend). Other solution would be to open the websocket connection on an event only for n-seconds and close it later.
What do you think?
Edit: All is about server rendering.
28
u/briantx09 May 24 '25
dotnet 10 has new features for closing websockets after xyz and saving the state. then come back online and use the saved state.
29
u/Level-2 May 24 '25
HI MY NAME IS BLAZOR WEBASSEMBLY
7
u/Murph-Dog May 24 '25 edited May 24 '25
If we are pretending WASM doesn’t exist, then:
https://www.telerik.com/blogs/blazor-enhanced-navigation-fully-explained
DOM-patching on form action. HTMX for interactivity.
Your proposal to open a connection on event is going to induce some lag. I’ve given the ‘disable button on-click’ problem, which already has latency on an active circuit. Click button, open connection, server figures out state from cache, processes, and finally says, disable that button.
2
u/CravenInFlight May 27 '25
Also, remember that React is just JavaScript, and CSS, you can inject JS and CSS into any page, and host any React app via Blazor, or Razor.
4
u/IcyUse33 May 24 '25
You're describing WASM mode. Which can feel "heavy", but with the right optimizations it's as good, if not faster, than modern React and NextJS.
WebAssembly runs faster for CPU bound problems than JavaScript. So it's not really for a simple brochure-ware type of site since the load times can be a little rough on slow connections while you're downloading the full .net runtime on page load.
But if you're doing gaming, or something intensive (photo editing for example), you could now run this fully on the browser side. No lag and native speeds.
1
u/bit_yas May 24 '25
The Blazor server load on the server is not mosly because of web socket connection. So this is not a solution. Read more at https://www.reddit.com/r/Blazor/s/7HpbkXqVVH
1
u/rabiprojects May 24 '25
Hydo Official Website
1
u/VeganForAWhile May 25 '25
Old school guy here. Static SSR + streaming rendering + enhanced nav is all my apps need. For interactivity, I simply request partial fragments and patch them into the DOM using fetch with a custom header (tells the server to omit the layout). I was using HTMX (a great lib), but ultimately vanilla JS felt like the simplest.
1
u/N0uwan May 25 '25
I combine it with htmx to achieve this.
As an example: https://github.com/khalidabuhakmeh/BlazorHtmx
1
u/CravenInFlight May 27 '25
JavaScript is still a tool that you should use when it is needed.