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.