3 ms·
you’d probably need to do some tricks to get it to parse in a browser. Editing, because I can’t reply: I was specifically going to mention SSE/EventSource but
by stephenr 7y ago
you’d probably need to do some tricks to get it to parse in a browser.
Editing, because I can’t reply: I was specifically going to mention SSE/EventSource but expected an immediate “not everything is a browser” response.
Editing the 2nd: yep, that’s kinda what I meant by “tricks” - essentially splitting out chunks to pass to the json parser.
- jwalton 7y agoSee my edited example above; you can stream data to this, it'll stream nicely to the browser. This uses "\n"s at the end of every line, which means you can write a very simple streaming parser client side, because you can just split the input at "\n," to get nice JSON bits, but there's certainly JSON streaming libraries on NPM that will parse this for you more "properly". And, it parses with a normal JSON parser too.
- pbedat 7y agoModern browsers understand text/event-stream so no need for dirty tricks ;)