Reputation: 841
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}
Upvotes: 1
Views: 2281
Reputation:
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();
}
Upvotes: 2