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

Asked

Viewed 86 times

0

I am trying to calculate the connection speed in MB of a user who access my site. But I couldn’t find much on the Internet other than ready-made programs and websites that already do that. The only thing I could do was 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 don’t know how to use this to calculate a user’s MB connection speed!

  • tamanho da pagina(em mb)/tempo de carregamento(s). That’s the basic operation, I just can’t guarantee that it’s that simple.

  • Or what I see many sites do is send a file to the cache and calculate how long it was downloaded by the user altogether. The calculation is the same, only changes the procedure, instead of its entire page, a file apart.

  • But with this formula it would be a bit tricky because every time I hear page change I will have to recalculate the size of it! :/

1 answer

1

You can do as per the @diegofm comment, but note that this measure will never give a certain value, for the following reasons:

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

This is why most measurement sites ask the user to close all programs that may be using the internet.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.