0

I've got a service accessed via HTTP on the server that is fairly long-running. I need a way to display the progress in the web browser while the XMLHttpRequest is in progress. I am trying to use the "progress" event, however the event never fires until the transfer is complete.

On the server side, I set the Content-Length header correctly, and then every second I send out a single byte to indicate progress. (This is just for testing. The idea is the actual process would send out one byte for every percent of progress.) On the client side I am setting up the progress event on the XMLHttpRequest, with the intent to see how many bytes have been received which will also be the percentage done. (100 bytes sent = 100% done)

If I connect to the server directly (e.g. telnet) I see it outputting a byte every 1 second. But in the web browser, I do not get any progress events until the entire transfer is done! A comment on another question suggested that the browser wouldn't start sending progress events until at least 69 bytes had been received, so for good measure I sent 100 bytes at the start. Yet, I still get no events.

Update: If I send 1000 bytes at the start I also don't get any progress events. But if I send 10000 bytes I do get events for almost every additional byte sent. Since the spec (as per the linked question) seems to suggest nowhere near this many bytes should be required, I'm a bit concerned as to whether I can rely on this to work across various browsers and platforms.

Michael
  • 9,060
  • 14
  • 61
  • 123
  • Not certain if `progress` event is dispatched based on response from server, but on data transmitted. – guest271314 May 25 '17 at 22:35
  • @guest271314 Wow. That linked question was so long-winded I didn't even manage to make it halfway through before giving up trying to figure out what it was trying to ask. – Michael May 25 '17 at 22:46
  • @guest271314 Also, had trouble parsing your comment... but my understanding is that progress event is dispatched by on data received from the server, and I am tailoring the server's response such that the amount of data received is proportional to the amount of server progress made. – Michael May 25 '17 at 22:47
  • @Micheal _"before giving up trying to figure out what it was trying to ask"_ Real-time communication between language-agnostic server implementation at server and `EventSource` at browser. At the Question, a `File` object is uploaded. Progress of the write of the file at server is streamed to client (browser). – guest271314 May 25 '17 at 22:47
  • Am not aware if any browser natively implements progress events of "download" from server. Though could be incorrect, here, as to previous sentence. – guest271314 May 25 '17 at 22:50

0 Answers0