Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XHR streaming closes connection by design?

I was reading this article: http://blog.pusher.com/what-came-before-websockets/, and the following text gets my attention:

XHR Streaming worked in all browsers the responseText of the XMLHttpRequest object would continue to grow until the connection was closed meaning a reconnection had to eventually be forced to clear this buffer.

If I understand this correctly, does this mean that whenever the buffer reaches certain size (what is the actual size here, by the way?), the connection will reset itself to clear up this buffer? In other words, XHR streaming is as long living as the size of this buffer?

Can someone please confirm this.

like image 299
skyork Avatar asked Feb 25 '13 21:02

skyork


1 Answers

XMLHttpRequest is not designed to be used in a streaming fashion. As long as the server sends more data, the browser will continue appending it to the responseText field in the XHR object.

Therefore, I'm pretty sure that what they meant is that the JS code using XHR for streaming would have to periodically drop the connection and open a new one — or else leak memory due to keeping all data ever received, as well as wasting time reallocating a forever-growing string.

That is, the limitation is one you must implement in order to have acceptable long-run performance, not one imposed by the browser. (There may well be also a browser-imposed cap on response size, but I don't know if there is.)

like image 112
Kevin Reid Avatar answered Oct 21 '22 07:10

Kevin Reid