-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement streaming in the browser #1033
Comments
I think that would be a good addition. We currently don't have an API to expose this functionality. The browser version doesn't support streaming at all. OTOH in Node we have Since I wonder how to have first-class support for node's streams, and first-class support for the Streams Standard without confusing and duplicated APIs. Do you have any proposal for the API? |
That's a tough question. I love superagent's clean API and minimal file size. And I also support building on standards. But I'm not sure how to join the two. Emulating/polyfilling Node streams or This issue for stream-http has a comment suggesting it would be possible to create a minimal stream library to replace the Node stream dependency to reduce file size. But, yes, creating yet another stream library would pollute superagent's clean API. |
I ran some quick tests on the minified, bundled sizes of the latest versions of related modules for comparison:
Here was the bundle command:
|
Maybe the best option would be to minimally polyfill the stream standard with a notice that the full stream standard will be used when it lands in most major browsers. The minimal polyfill would be limited to event emitters ( |
Yes, I think a minimal polyfill is a good way to go. With XHR we don't even have ability to do proper backrpessure. |
Hmm... WHAT-WG streams actually remove |
Also, there is the observable standard, which is probably less suited for the purpose of this library, but it does offer yet another way of working with multiple chunks over time. If for some reason the observable standard gets traction and the stream standard doesn't, then it would make sense to use the observable standard here. |
But if we continue with the web streams standard, the |
If the polyfill is heavy I see a couple of possible workarounds:
|
I like the second idea. Would the hooks be event emitters and In this issue, there's some interesting discussion on lightweight transforms for web streams. Would the hooks be easy to use with transducers? |
Currently superagent, in node version, has a rather ad-hoc mechanism for "parsers" https://github.com/visionmedia/superagent/blob/master/lib/node/parsers/text.js which boils down to "data" and "end" events. Is that equivalent of |
Yes, that sounds perfect. |
So, currently if the server is sending the response in chunks, there is no way to receive it accordingly on the browser? |
Depends what you mean by chunks. If you mean chunked HTTP/1.1, then you can, but superagent will wait until the whole response is received. |
Well, on the server I subscribe to a stream which is emitting data when they are available (that's what I mean by chunks). But because sending the whole response takes long (fetching one year's data), the client is always throwing a |
Streaming in the browser will not solve your problem, as the error is due to your web server cutting the connection server-side. |
Is there any way to verify that? The server seems to be sending data normally, without any errors. |
Try using raw |
I tried using an |
If you get error in It's most likely that it's a problem outside of browser, e.g. in your CDN, your reverse proxy, your web server, or middleware managing node. |
|
The current use of chunked transfer encoding is based on
xhr.responseText
. There are now more efficient methods available for Firefox (moz-chunked-text
) and Chrome (ReadableByteStream
). Would there be any interest in using those methods when possible?It would be awesome if superagent supported streaming in the browser along the lines of what this library offers. I'd be willing to contribute if there's any interest.
The text was updated successfully, but these errors were encountered: