I’ve never understood the use of SSE over ndjson. Builtin browser support for SSE might be nice, but it seems fairly easy to handle ndjson? For non-browser consumers ndjson is almost assuredly easier to handle. ndjson works over any transport from HTTP/0.9 to HTTP/3 to raw TCP or unix sockets or any reliable transport protocol.
Manually streaming a XHR and parsing the messages is significantly more work, and you lose the built-in browser API. But if you use a fetch ReadableStream with TLV messages I'm sold.
Server-Sent Events (SSE) Are Underrated
61–70 of 153 posts
Re: Server-Sent Events (SSE) Are Underrated
#62They're underrated when they work™ Currently at work I'm having issues because - Auth between an embedded app and javascript's EventSource is not working, so I have to resort to a Microsoft package which doesn't always work. - Not every tunnel is fond of keep-alive (Cloudflare), so I had to switch to ngrok (until I found out they have a limit of 20k requests). I know this isn't the protocol's fault, and I'm sure ther…
Re: Server-Sent Events (SSE) Are Underrated
#63It doesn’t mention the big drawback of SSE as spelled out in the MDN docs: “Warning: When not used over HTTP/2, SSE suffers from a limitation to the maximum number of open connections, which can be especially painful when opening multiple tabs, as the limit is per browser and is set to a very low number (6).”
That is a very low number. I can think of many reasons why one would end up with more. Does anyone know why it is so low?
While server capacity in every dimension has increased the low connection count for browsers has remained. But even today it's still a bit of a courtesy to not spam a server with a hundred simultaneous connections. If the server implicitly supports tons of connects with HTTP/2 support that's one thing but it's not polite to abuse HTTP/1.1 servers.
Re: Server-Sent Events (SSE) Are Underrated
#64Earlier quoted context omitted.
And over HTTP/2 and 3 they are efficient?
HTTP/2+ only uses a single transport connection (TCP or QUIC) per server, and multiplexes over that. So there's essentially no practical limit.
Re: Server-Sent Events (SSE) Are Underrated
#65Earlier quoted context omitted.
Corporate proxy servers often downgrade connections to HTTP 1.1 because inertia and lazy vendors.
To do that they need to MITM and tamper with the inner protocol. In my experience this is quite rare. Some MITM proxies analyze the traffic, restrict which ciphers can be used, block non-dns udp (and therefore HTTP/3), but they don't usually downgrade the protocol from HTTP/2 to HTTP/1.
Re: Server-Sent Events (SSE) Are Underrated
#66Earlier quoted context omitted.
You can easily multiplex data over one connection/event stream. You can design your app so that it only uses one eventstream for all events it needs to receive.
This, it works well in a service worker for example.
Re: Server-Sent Events (SSE) Are Underrated
#67A while ago I created Mercure: an open pub-sub protocol built on top of SSE that is a replacement for WebSockets-based solutions such as Pusher. Mercure is now used by hundreds of apps in production. At the core of Mercure is the hub. It is a standalone component that maintains persistent SSE (HTTP) connections to the clients, and it exposes a very simple HTTP API that server apps and clients can use to publish. POST…
Re: Server-Sent Events (SSE) Are Underrated
#68Earlier quoted context omitted.
Corporate proxy servers often downgrade connections to HTTP 1.1 because inertia and lazy vendors.
To do that they need to MITM and tamper with the inner protocol. In my experience this is quite rare. Some MITM proxies analyze the traffic, restrict which ciphers can be used, block non-dns udp (and therefore HTTP/3), but they don't usually downgrade the protocol from HTTP/2 to HTTP/1.
Re: Server-Sent Events (SSE) Are Underrated
#69Re: Server-Sent Events (SSE) Are Underrated
#70Earlier quoted context omitted.
Presumably you try SSE, and on failure fallback to something else like WebSockets? Push seems to require supporting multiple communication protocols to avoid failure modes specific to one protocol - and libraries are complex because of that.
But then why not just use websockets?