0

How can I detect internet connection speed and / or bandwidth in javascript?

Something that has an isSlow() like function would be nice because I don't really understand how to interpret the values for connection speed and know what is slow and what is not.

JayGatz
  • 271
  • 1
  • 8
  • 18
  • http://stackoverflow.com/questions/4547166/bandwidth-utility-using-javascript/4547184#4547184 – Joe Slater Jun 15 '13 at 15:34
  • http://stackoverflow.com/questions/5529718/how-to-detect-internet-speed-in-javascript?rq=1 – Joe Slater Jun 15 '13 at 15:37
  • 1
    you won't find a useful `isSlow()` function, because slowness is always relative – it might be slow connection for HD video streaming but perfect for SD video streaming – Beat Jun 15 '13 at 15:39
  • @Beat then how do I determine what is sfast enough for multiple ajax requests and what is too slow to skip them. – JayGatz Jun 15 '13 at 17:26
  • @JayGatz If you're just sending some Ajax requests and receiving a few KB of response, it's less about bandwidth but more about delay. If you'd tell us more about the application, we could give you better advice. – Beat Jun 15 '13 at 22:08
  • @Beat On key up, I give the user instant suggestions by searching for their current query as they are typing it. – JayGatz Jun 16 '13 at 16:29
  • @JayGatz for this use case the user's bandwidth is really not your problem – you're sending so few data. But you'll bombard your server with many requests and most of the responses will never be used because the user has typed yet another character. Have you considered waiting before sending a request until the user hast stopped typing for like half a second? – Beat Jun 17 '13 at 11:54

1 Answers1

1
window.test_start = new Date();
$.get('10mbfile.dat',function(){
   var test_end = new Date();
   var result =  10 / (test_end - test_start); // mb/s 
});
Flash Thunder
  • 11,672
  • 8
  • 47
  • 91