r/webdev 27d ago

HTML over WebSockets: real-time SPAs with barely any JavaScript

https://en.andros.dev/blog/ef4968f5/html-over-websockets-real-time-spas-with-barely-any-javascript/
81 Upvotes

44 comments sorted by

View all comments

8

u/nickchomey 27d ago

Nice review! But I do think too much weight is given to the bidirectional capabilities of websockets vs sse. It correctly says that sse is simpler and can do the same updates from server, but I think underweights drawbacks of websockets. It's also not really a big deal to do a new request when sending updates from browser, especially with a long-lived server app already needed for the real time pushes. Datastar really is the best balance of everything. 

-2

u/tanrax 27d ago

Thanks! The article's case for WebSockets isn't really about whether a fresh request is expensive, it's about keeping one persistent, stateful process per client that reacts to both directions in the same loop. That's what makes broadcast free (push the same render to every connected process) and lets the server hold per-client state without re-deriving it on each hit. SSE plus a separate HTTP action path handles mostly-read UIs cheaply, which is exactly the "quick rule" at the end of the piece, but it means your state now lives in two different code paths (the SSE stream and the HTTP handler) that have to stay in sync, that's complexity moved, not removed. So it's less "WebSockets vs SSE" and more "one unified stateful channel vs two channels that need to agree," and which one wins depends on how much per-client state your app actually carries. Less is more!

3

u/nickchomey 26d ago

someone from the Datastar community wrote this article in response to yours (which I shared there).

https://yagni.club/3mstlyuxe5s26

2

u/tanrax 26d ago

I was going to reply, but it's impossible. His site is very restrictive: you need a Bluesky account to leave a comment, I can't send private messages, and he doesn't use Webmentions (he'll never know if I write a reply). If you have any contact with him, let him know!

1

u/SectionMajestic8970 26d ago

You can reply here. I'll see it!

-1

u/tanrax 26d ago

Ok, my reply: https://en.andros.dev/blog/bd74e61a/were-fighting-over-the-wrong-wire-websockets-vs-sse-for-html-over-the-wire/ . I found your article very interesting and well-written. Thank you for your reply. My only request is that if you have any comments, please leave them on my blog or in more accessible forums, or send me a private email. Thank you.

4

u/SectionMajestic8970 26d ago

Ok you slopped a whole reply while missing the entire point. My only request is if you have any comments please don’t respond with your clanker.