Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-03-2012, 11:21 PM   PM User | #1
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
Detect user's connection speed

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?

Thanks.
johnsmith153 is offline   Reply With Quote
Old 09-03-2012, 11:29 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
It can't be done in Javascript. Possibly flash or Java.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 09-03-2012, 11:34 PM   PM User | #3
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
Rubbish, and it's JavaScript and Flash, not Javascript and flash.
johnsmith153 is offline   Reply With Quote
Old 09-04-2012, 01:11 AM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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%

Last edited by rnd me; 09-04-2012 at 01:14 AM..
rnd me is offline   Reply With Quote
Old 09-04-2012, 01:22 AM   PM User | #5
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Quote:
Originally Posted by johnsmith153 View Post
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!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 09-04-2012, 01:24 AM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by _Aerospace_Eng_ View Post
It can't be done in Javascript.
please don't ever say that again.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 09-04-2012, 01:51 AM   PM User | #7
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,615
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Quote:
Originally Posted by rnd me View Post
please don't ever say that again.
How do bake a cookie with JavaScript?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 09-04-2012, 04:33 AM   PM User | #8
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
Quote:
Originally Posted by rnd me View Post
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.

Thanks again.
johnsmith153 is offline   Reply With Quote
Old 09-04-2012, 07:16 AM   PM User | #9
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by johnsmith153 View Post
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.

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%
rnd me is offline   Reply With Quote
Old 09-04-2012, 10:49 AM   PM User | #10
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
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.
Good point. Thanks.
johnsmith153 is offline   Reply With Quote
Old 09-04-2012, 08:38 PM   PM User | #11
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by johnsmith153 View Post
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%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 PM.


Advertisement
Log in to turn off these ads.