Re:WebSockets vs. Server-Sent-Events vs. Long-Polling vs. We...
by apitman on Monday March 18, 2024 @03:46PM
(#39749080)
I've implemented SSE from scratch on the server and XHR streaming/parsing from scratch on the client side (which would be necessary for JSONL), and SSE was way simpler. Unless there's another way to do JSONL in a browser that I'm not aware of?
[ Parent
| on HN ]
Re:WebSockets vs. Server-Sent-Events vs. Long-Polling vs. We...
by bterlson on Monday March 18, 2024 @05:10PM
(#39750063)
If you use the fetch API you can get a readable stream and party on without too much difficulty. You can also implement a transform stream in ~10SLOC that will make the reader vend parsed JSON objects and can be reused easily.
Re:WebSockets vs. Server-Sent-Events vs. Long-Polling vs. We...
by apitman on Monday March 18, 2024 @07:43PM
(#39751406)
This is a good point. In fact, you just helped me realize that I can probably replace this[0] at work with a fetch implementation. ReadableStreams weren't generally available across browsers when I wrote that. This would also allow us to return binary data if we so desired (XHR can handle binary but it can't stream it chunk by chunk). Thanks!