/* HTML5 Speedtest v4.7 MPOT - Server selector by Federico Dossena https://github.com/adolfintel/speedtest/ GNU LGPLv3 License */ //pings the specified URL, then calls the function result. Result will receive a parameter which is either the time it took to ping the URL, or -1 if something went wrong. var PING_TIMEOUT=1000; var USE_PING_TIMEOUT=true; //will be disabled on unsupported browsers if(/MSIE.(\d+\.\d+)/i.test(navigator.userAgent)){ //IE11 doesn't support XHR timeout USE_PING_TIMEOUT=false; } function ping(url,result){ var xhr=new XMLHttpRequest(); var t=new Date().getTime(); xhr.onload=function(){ if(xhr.responseText.length==0){ //we expect an empty response var instspd=new Date().getTime()-t; //rough timing estimate try{ //try to get more accurate timing using performance API var p=performance.getEntries(); p=p[p.length-1]; var d=p.responseStart-p.requestStart; if(d<=0) d=p.duration; if(d>0&&d=0){ if(t