Added minified JS; Updated examples

This commit is contained in:
adolfintel 2018-08-15 08:38:39 +02:00
parent 724c450821
commit c5913d1a6c
4 changed files with 56 additions and 22 deletions

View file

@ -1,25 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="server_selector.js"></script>
<script type="text/javascript" src="server_selector.min.js"></script>
<script type="text/javascript">
function I(i){return document.getElementById(i);}
//LIST OF TEST SERVERS. See documentation for details if needed
var SPEEDTEST_SERVERS=[
{ //this is my demo server, remove it
name:"Speedtest Demo Server (fdossena.com)", //user friendly name for the server
server:"https://speedtest.fdossena.com/testing/", //Full URL to the server, complete with / at the end
name:"Speedtest Demo Server 1 (HTTP)", //user friendly name for the server
server:"http://mpotdemo.fdossena.com/", //Full URL to the server, complete with / at the end
dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
},
{
name:"Localhost",
server:"http://127.0.0.1/",
dlURL:"garbage.php",
ulURL:"empty.php",
{ //this is my demo server, remove it
name:"Speedtest Demo Server 2 (HTTP)",
server:"http://mpotdemo.adolfintel.com/",
dlURL:"garbage.php",
ulURL:"empty.php",
pingURL:"empty.php",
getIpURL:"getIP.php"
},
{ //this is my demo server, remove it
name:"Speedtest Demo Server 1 (HTTPS)",
server:"https://mpotdemo.fdossena.com/",
dlURL:"garbage.php",
ulURL:"empty.php",
pingURL:"empty.php",
getIpURL:"getIP.php"
},
{ //this is my demo server, remove it
name:"Speedtest Demo Server 2 (HTTPS)",
server:"https://mpotdemo.adolfintel.com/",
dlURL:"garbage.php",
ulURL:"empty.php",
pingURL:"empty.php",
getIpURL:"getIP.php"
}
@ -104,7 +120,7 @@ function startStop(){
initUI();
}else{
//test is not running, begin
w=new Worker('speedtest_worker.js');
w=new Worker('speedtest_worker.min.js');
w.postMessage('start '+JSON.stringify(speedtestSettings)); //Add optional parameters as a JSON object to this command
I("startStopBtn").className="running";
w.onmessage=function(e){
@ -178,7 +194,7 @@ function initUI(){
color:#404040;
text-align:center;
}
div.loadCircle{
span.loadCircle{
display:inline-block;
width:2em;
height:2em;
@ -311,7 +327,7 @@ function initUI(){
<body onload="initServers()">
<h1>HTML5 Speedtest</h1>
<div id="loading" class="visible">
<p id="message"><div class="loadCircle"></div>Selecting a server...</p>
<p id="message"><span class="loadCircle"></span>Selecting a server...</p>
</div>
<div id="testWrapper" class="hidden">
<div id="startStopBtn" onclick="startStop()"></div>

View file

@ -1,25 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="server_selector.js"></script>
<script type="text/javascript" src="server_selector.min.js"></script>
<script type="text/javascript">
function I(i){return document.getElementById(i);}
//LIST OF TEST SERVERS. See documentation for details if needed
var SPEEDTEST_SERVERS=[
{ //this is my demo server, remove it
name:"Speedtest Demo Server (fdossena.com)", //user friendly name for the server
server:"https://speedtest.fdossena.com/testing/", //Full URL to the server, complete with / at the end
name:"Speedtest Demo Server 1 (HTTP)", //user friendly name for the server
server:"http://mpotdemo.fdossena.com/", //Full URL to the server, complete with / at the end
dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
},
{
name:"Localhost",
server:"http://127.0.0.1/",
dlURL:"garbage.php",
ulURL:"empty.php",
{ //this is my demo server, remove it
name:"Speedtest Demo Server 2 (HTTP)",
server:"http://mpotdemo.adolfintel.com/",
dlURL:"garbage.php",
ulURL:"empty.php",
pingURL:"empty.php",
getIpURL:"getIP.php"
},
{ //this is my demo server, remove it
name:"Speedtest Demo Server 1 (HTTPS)",
server:"https://mpotdemo.fdossena.com/",
dlURL:"garbage.php",
ulURL:"empty.php",
pingURL:"empty.php",
getIpURL:"getIP.php"
},
{ //this is my demo server, remove it
name:"Speedtest Demo Server 2 (HTTPS)",
server:"https://mpotdemo.adolfintel.com/",
dlURL:"garbage.php",
ulURL:"empty.php",
pingURL:"empty.php",
getIpURL:"getIP.php"
}
@ -104,7 +120,7 @@ function startStop(){
initUI();
}else{
//test is not running, begin
w=new Worker('speedtest_worker.js');
w=new Worker('speedtest_worker.min.js');
w.postMessage('start '+JSON.stringify(speedtestSettings)); //Add optional parameters as a JSON object to this command
I("startStopBtn").className="running";
I("shareArea").style.display="none";
@ -192,7 +208,7 @@ function initUI(){
color:#404040;
text-align:center;
}
div.loadCircle{
span.loadCircle{
display:inline-block;
width:2em;
height:2em;
@ -337,7 +353,7 @@ function initUI(){
<body onload="initServers()">
<h1>HTML5 Speedtest</h1>
<div id="loading" class="visible">
<p id="message"><div class="loadCircle"></div>Selecting a server...</p>
<p id="message"><span class="loadCircle"></span>Selecting a server...</p>
</div>
<div id="testWrapper" class="hidden">
<div id="startStopBtn" onclick="startStop()"></div>

1
Frontend/server_selector.min.js vendored Normal file
View file

@ -0,0 +1 @@
function ping(url,result){var xhr=new XMLHttpRequest,t=(new Date).getTime();xhr.onload=function(){if(0==xhr.responseText.length){var instspd=(new Date).getTime()-t;try{var p=performance.getEntries(),d=(p=p[p.length-1]).responseStart-p.requestStart;d<=0&&(d=p.duration),0<d&&d<instspd&&(instspd=d)}catch(e){}result(instspd)}else result(-1)}.bind(this),xhr.onerror=function(){result(-1)}.bind(this),xhr.open("GET",url),xhr.send()}var PINGS=3,SLOW_THRESHOLD=500;function checkServer(server,done){var i=0;server.pingT=-1;var nextPing=function(){i++!=PINGS?ping(server.server+server.pingURL,function(t){0<=t?((t<server.pingT||-1==server.pingT)&&(server.pingT=t),t<SLOW_THRESHOLD?nextPing():done()):done()}.bind(this)):done()}.bind(this);nextPing()}function selectServer(serverList,result){var i=0,done=function(){for(var bestServer=null,i=0;i<serverList.length;i++)-1!=serverList[i].pingT&&(null==bestServer||serverList[i].pingT<bestServer.pingT)&&(bestServer=serverList[i]);result(bestServer)}.bind(this),nextServer=function(){i!=serverList.length?checkServer(serverList[i++],nextServer):done()}.bind(this);nextServer()}var CONCURRENCY=4;function fastSelectServer(serverList,result){for(var serverLists=[],i=0;i<CONCURRENCY;i++)serverLists[i]=[];for(i=0;i<serverList.length;i++)serverLists[i%CONCURRENCY].push(serverList[i]);var completed=0,bestServer=null;for(i=0;i<CONCURRENCY;i++)selectServer(serverLists[i],function(server){null!=server&&(null==bestServer||server.pingT<bestServer.pingT)&&(bestServer=server),++completed==CONCURRENCY&&result(bestServer)}.bind(this))}

1
Frontend/speedtest_worker.min.js vendored Normal file

File diff suppressed because one or more lines are too long