Last active
July 26, 2017 09:18
-
-
Save richorama/6340426 to your computer and use it in GitHub Desktop.
Programmatically determine your nearest Windows Azure Data Centre
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script> | |
var locations = { | |
"speedtestwe": "West Europe", | |
"speedtestsea" : "Southeast Asia", | |
"speedtestea": "East Asia", | |
"speedtestnsus": "North Central US", | |
"speedtestne": "North Europe", | |
"speedtestscus": "South Central US", | |
"speedtestwus": "West US", | |
"speedtesteus": "East US", | |
"speedtestjpe": "Japan East", | |
"speedtestjpw": "Japan West" | |
}; | |
var i = 1; | |
// This function is called when each Data Center responds. | |
// The first to respond is the nearest! | |
function call(name){ | |
console.log(i + ":" + locations[name]); | |
i++; | |
} | |
for(var name in locations){ | |
append(name); | |
} | |
function append(name){ | |
var head = document.getElementsByTagName("head")[0]; | |
var newscrpt; | |
newscrpt = document.createElement('script'); | |
newscrpt.type = "text/javascript" ; | |
newscrpt.src = "//" + name + ".blob.core.windows.net/cb.json"; | |
newscrpt = head.appendChild(newscrpt); | |
} | |
</script> | |
</head> | |
<body>Results are in the console</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMO, A brilliant and elegant solution.