xdomain icon indicating copy to clipboard operation
xdomain copied to clipboard

Feature: Streaming responses

Open peterjosling opened this issue 10 years ago • 4 comments

The XHR emits progress events as per the spec, but doesn't populate the response/responseText properties until the request has completed, so it's impossible to utilise streaming requests (for things such as Twitter's streaming API).

peterjosling avatar Jul 16 '14 09:07 peterjosling

Very true, response/text is not set per progress.

As an aside, I briefly tested Twitter's API with XMLHttpRequest and it wasn't very fun, had to pull the current text and diff it with what I had already processed. This would get slower and slower the longer you stream. Have you also encountered this?

jpillora avatar Jul 16 '14 09:07 jpillora

Previously I've just stored the length of the response body from the previous progress event and then pulled out the substring from that index onwards. Speed's never been an issue - I just put in a check to close and reopen the stream if the response grew over a few MB in size (as you can't clear it).

peterjosling avatar Jul 16 '14 09:07 peterjosling

Ah yep, length slicing + reopening the stream seems like a good solution. This shouldn't be too hard to add, will look into it tonight

jpillora avatar Jul 16 '14 09:07 jpillora

+1 This is what Yaffle/EventSource does and it would be great to have these two polyfills work together better.

mscdex avatar Jul 21 '14 18:07 mscdex