XMLHttpRequest provides the ability to listen to various events that can occur while the request is being processed. Beneath those also is progress
It checks if the amount of data that has been retrieved has changed.
var oReq = new XMLHttpRequest();
oReq.addEventListener("progress", updateProgress);
oReq.open("GET", url);
// progress on transfers from the server to the client (downloads)
function updateProgress (oEvent) {
if (oEvent.lengthComputable) {
// DO your Stuff here
} else {
// Unable to compute progress information since the total size is unknown
}
}
Note: You need to add the event listeners before calling open() on the
request. Otherwise the progress events will not fire.