I want to detect the user's connection speed to offer an improved website experience. As an example, use 20 records per page pagination, but allow the detection script to change that to higher or lower (as well as other things).
How is the best way to do this, and can someone point me in the right direction?
using this, i'd say anything over 50 would be fast, anything over 500 would be really fast:
Code:
function getRate() {
var sum = 0;
for (var i = 0; i < 5; i++) {
var d1 = new Date;
var X = new XMLHttpRequest;
X.open("GET", "?" + Math.random(), false);
X.send();
var d2 = new Date;
sum += (d2 - d1);
}//next
return Math.floor(X.responseText.length / (sum / 5));
} /* end getRate() */
alert(
getRate() + "KBs"
)
remember, a modem is 5 or 6 on a good day...
not too difficult to program either...
__________________ my site (updated 5/13) STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
Rubbish, and it's JavaScript and Flash, not Javascript and flash.
Then why didn't you answer your own question? It would seem to me if you think it is "rubbish" then you would know how to do it on your own. Learn to be considerate of the people trying to help. Good luck. Hope you find what you are looking for, oh wait you probably don't need any help.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
using this, i'd say anything over 50 would be fast, anything over 500 would be really fast:
Code:
function getRate() {
var sum = 0;
for (var i = 0; i < 5; i++) {
var d1 = new Date;
var X = new XMLHttpRequest;
X.open("GET", "?" + Math.random(), false);
X.send();
var d2 = new Date;
sum += (d2 - d1);
}//next
return Math.floor(X.responseText.length / (sum / 5));
} /* end getRate() */
alert(
getRate() + "KBs"
)
remember, a modem is 5 or 6 on a good day...
not too difficult to program either...
Brilliant. Thanks.
Only thing is:
Code:
new Date;
should be:
Code:
new Date().getTime() / 100;
I've tested and it works great on many occasions and on many different devices.
So much better than the image download scripts I keep seeing.
I've tested and it works great on many occasions and on many different devices.
So much better than the image download scripts I keep seeing.
Thanks again.
my units are KiloBytes per second, you might be looking for KiloBits per second, which is more common in ISP advertising.
i should also mention that you might consider is keeping track of the total time, subtracting delay and the dividing by 5. That math yields your average latency, another quality of service indicator.
__________________ my site (updated 5/13) STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
Thanks, but your script returned a score of 1-4 units depending on how I tested it (and I tested it on lots of different connection speeds).
Changing it as I have returns 1-400 units.
It definitely needed changing. You said that anything over 50 would be fast, and 500 would be really fast. Your script would never return anything near 50, let alone 500.
Quote:
i should also mention that you might consider is keeping track of the total time, subtracting delay and the dividing by 5. That math yields your average latency, another quality of service indicator.
Thanks, but your script returned a score of 1-4 units depending on how I tested it (and I tested it on lots of different connection speeds).
Changing it as I have returns 1-400 units.
It definitely needed changing. You said that anything over 50 would be fast, and 500 would be really fast. Your script would never return anything near 50, let alone 500.
Good point. Thanks.
i'm glad you got it working, but when i run the code in post #4 at home i get about 60-90 (crappy wifi). at work i get ~180...
__________________ my site (updated 5/13) STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%