开发者

Download estimator using JavaScript and Ajax

开发者 https://www.devze.com 2022-12-23 13:38 出处:网络
I would like to implement the download estimator using the JavaScript and the Ajax. I have gone trough Google, existing posts on stackoverflow also to find the existing implementations for the downl

I would like to implement the download estimator using the JavaScript and the Ajax.

I have gone trough Google, existing posts on stackoverflow also to find the existing implementations for the download estimator and i found most of the time asking user bandwidth and then calculating the number is strategy. It good approach and there is hardly anything on reliable to get the estimated time right.

What i would like to try is use Ajax to request file size 100KB - 200 KB and do the maths get the number and update the display. Now this is surrounded with so many questions like network, number of packets formed, proxies etc ? These all factors are sufficient to turn down the approach. But THIS IS HOW I HAVE TO DO THIS.

Now i would like here inputs from you all to make it better (as good discussion)? what all can be added to this ? Can we get to know bandwidth user using without asking ?开发者_Go百科 How can it can be made better ?


You could technically test the bandwidth yourself by including a timestamp in the initial page request with the size, and calculate against the current time in the browser.

var size = $size; //in KB
var timestamp = $timestamp;
var currTime = new Date().getTime();
var kbps = size / ((currTime-timestamp)/1000);

Here my $ notation indicates a variable that gets templated in on the server. This would obviously not be perfect, but it would be more accurate than asking the user.

0

精彩评论

暂无评论...
验证码 换一张
取 消