how can I get the % of a image loading on my server and show % of it's loading. That's what I use to load image(it's for a simple download speed test).
var imageAddr = 'http://192.168.11.17/Cat2.JPG' + '?n=' + Math.random();
var startTime, endTime;
var downloadSize = 7616998;
var download = new Image();
download.onload = function () {
endTime = (new Date()).getTime();
showResults();
}
startTime = (new Date()).getTime();
download.src = imageAddr;
function showResults() {
var duration = (endTime - startTime) / 1000;
var bitsLoaded = downloadSize * 8;
var speedBps = (bitsLoaded / duration).toFixed(2);
var speedKbps = (speedBps / 1024).toFixed(2);
var speedMbps = (speedKbps / 1024).toFixed(2);
var speedMB = speedMbps / 8;
document.getElementById('download').innerHTML = speedMbps + 'Mbps';
}
Maybe there is other solutions with XMLHTTPRequest but I've tried with no succes. Thanks.