4 ms·
This is probably naive, but it seems like assuming HTTP/2 or better, an EventSource combined with fetch() for sending messages should be just as good as any oth
by skybrian 3y ago
This is probably naive, but it seems like assuming HTTP/2 or better, an EventSource combined with fetch() for sending messages should be just as good as any other protocol that uses a single TCP connection? And HTTP/3 uses UDP, so even better.
(This all assumes you only care about maintaining a connection when the tab is in the foreground.)
I’m wondering what problems people have run into when they tried this.
- jacobr1 3y agoThis presumes the majority of your use case is server-client, but otherwise yes.
- apitman 3y agoOne limitation is SSE is text-only, so you can't efficiently send binary data. You have to encode it as base64 or similar.
- niutech 3y agoThere is another alternative to base64: https://github.com/luciopaiva/binary-sse https://github.com/luciopaiva/binary-sse
- ksec 3y agoWas thinking exactly the same thing. H2 with SSE solves 99% of problems? I was wondering if we could push SSE even further along with lower latency, memory usage and CPU resources than doing something completely different.
- nchmy 3y agoThis library does what you are looking for https://www.npmjs.com/package/@microsoft/fetch-event-source https://www.npmjs.com/package/@microsoft/fetch-event-source