xdomain
xdomain copied to clipboard
Feature: Streaming responses
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).
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?
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).
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
+1 This is what Yaffle/EventSource does and it would be great to have these two polyfills work together better.