How to calculate the speed of a user's internet connection?

0

I'm trying to calculate the speed of the connection in MB of a user who accesses my site. But I could not find much on the internet besides programs that are ready and sites that already do that. The only thing I was able to do was to calculate how long in milliseconds the page takes to load:

$(window).load(function () {
       var endTime = (new Date()).getTime();
       var millisecondsLoading = endTime - startTime;
       console.log(millisecondsLoading);
       // Put millisecondsLoading in a hidden form field
       // or Ajax it back to the server or whatever.
   });

But I do not know how to use this to calculate the connection speed in a user's MB!

    
asked by anonymous 02.05.2017 / 15:12

1 answer

1

You can do according to @diegofm's comment, however, see that this measure will never give a certain value for the following reasons:

  • The connection may oscillate;
  • The route to your site may vary according to each internet provider
  • If the user has 10 tabs on YouTube, for example loading, the time will be different.

That's why most measurement sites ask the user to close all programs that might be using the internet.

But you still want, as I said, @diegofm's solution is even simple to implement. Save a 1Kb cache for example and calculate the time

    
02.05.2017 / 15:54