1

Is it possible to detect, through Javascript, whether the user is connected to a WIFI or high speed connection as opposed to a slow one? I'm trying to use something like that to load a compressed version of a video if the user is on a slow connection.

Like: if (onwifi) { //heavy video } else { //light video}

Danny Garcia
  • 831
  • 2
  • 8
  • 24
  • 1
    This is more of a question about detecting connection speed and is related to http://stackoverflow.com/questions/4185266/html5-video-for-iphone-ipad-how-to-detect-connection-speed – nedk Jan 15 '11 at 01:33

1 Answers1

2

Yes, you can gauge the connection speed.

Create a new Date object, then use the DOM to download an image of a fixed size, with a random number appended on the end so the client doesn't cache it. The image's onload event should subtract the time before the image was downloaded from the current time, therefore giving you the number of milliseconds it took to download.

var imageurl='http://www.google.com/intl/en_ALL/images/srpr/logo1w.png';
var image=document.createElement('image');
image.src=imageurl+'?'+Math.round(Math.random()*1000);
document.body.appendChild(image);
var imagetook=0;
var date=new Date();
image.onload=function(){
    imagetook=getMilliseconds();
    startmovie();
}