Skip to content

Instantly share code, notes, and snippets.

@richorama
Last active July 26, 2017 09:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save richorama/6340426 to your computer and use it in GitHub Desktop.
Save richorama/6340426 to your computer and use it in GitHub Desktop.
Programmatically determine your nearest Windows Azure Data Centre
<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>
@andreujuanc
Copy link

IMO, A brilliant and elegant solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment