Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Rubbish, and it's JavaScript and Flash, not Javascript and flash.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    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...
    Last edited by rnd me; 09-04-2012 at 02:14 AM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    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 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,876
    Thanks
    6
    Thanked 1,035 Times in 1,008 Posts
    Quote Originally Posted by rnd me View Post
    please don't ever say that again.
    How do bake a cookie with JavaScript?

  • #8
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    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 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #10
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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.

    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.

  • #11
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    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 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •