News for hackers. Stuff that matters.
Re:You might not need WebSockets by jongjong on Friday April 11, 2025 @08:16PM (#43660111)
I don't know why people keep trying desperately to avoid the simplicity and flexibility of WebSockets.

A lot of times, what people need is a bidirectional connection yet somehow they convince themselves that SSE (or sometimes even long polling is better for the job)... But they end up with two different types of streams; HTTP for writes and responses and SSE for passively consuming real-time data... Two different stream types with different lifecycles; one connection could fail while the other is fine... There is no way to correctly identify what is the current connection status of the app because there are multiple statuses and data comes from multiple streams.

Re:You might not need WebSockets by hntrl on Friday April 11, 2025 @08:38PM (#43660241)
who's to say your data is coming from multiple streams? You can propagate any updates you need to make in the application to a single stream (like SSE or a long-lived response) in place of a WebSocket. your http responses can just be always 204 if all they're doing is handling updates and pushing events to aforementioned single stream.

https://en.wikipedia.org/wiki/Command%E2%80%93query_separati...

Re:You might not need WebSockets by koakuma-chan on Friday April 11, 2025 @09:02PM (#43660349)
SSE does not require a separate connection, unlike WebSockets.
Re:You might not need WebSockets by kaoD on Friday April 11, 2025 @10:04PM (#43660671)
MDN disagrees. See the huge red warning here https://developer.mozilla.org/en-US/docs/Web/API/EventSource

Unless you mean on HTTP2? But aren't WS connections also multiplexed over HTTP2 in that case?

Re:You might not need WebSockets by koakuma-chan on Friday April 11, 2025 @10:12PM (#43660707)
> MDN disagrees. See the huge red warning here https://developer.mozilla.org/en-US/docs/Web/API/EventSource

It should say "When used over HTTP/1" instead of "When not used over HTTP/2" because nowadays we also have HTTP/3, and browsers barely even use HTTP/1, so I would say it's pretty safe to ignore that warning.

> Unless you mean on HTTP2?

Any version of HTTP that supports multiplexing.

> But aren't WS connections also multiplexed over HTTP2 in that case?

There is RFC 8441 but I don't think it's actually implemented in the browsers.

Re:You might not need WebSockets by kaoD on Friday April 11, 2025 @10:38PM (#43660839)
> There is RFC 8441 but I don't think it's actually implemented in the browsers.

Found this: https://github.com/mattermost/mattermost/issues/30285

Re:You might not need WebSockets by koakuma-chan on Friday April 11, 2025 @11:32PM (#43661101)
https://chromestatus.com/feature/6251293127475200

It looks like it's supported in Chrome and Firefox but not in Safari.

Re:You might not need WebSockets by gorjusborg on Friday April 11, 2025 @10:34PM (#43660800)
I don't know why everyone... proceeds to use their own experience as proof of what everyone needs.

These are tools, not religions.

Websockets have some real downsides if you don't need bidirectional comms.