|
|
|
|
|
by trosc
4584 days ago
|
|
Why not let website visitors make your measurements by loading the JavaScript files from the CDNs in the background? Something like (untested): var i = 0;
var urls = [
"http://cdn.jsdelivr.net/jquery/2.0.3/jquery-2.0.3.min.js",
"http://code.jquery.com/jquery-2.0.3.min.js",
...
];
function measureRemaining() {
if(i >= urls.length) return;
var url = urls[i++];
measureLatency(url, function(latency) {
// TODO: post (url,latency) to back-end
measureRemaining();
});
}
function measureLatency(url,responseFn) {
var script = document.createElement("script");
// Bust through browser cache
script.src = url + "?bust=" + Math.random():
var start = new Date().getTime();
script.onload = function() {
var end = new Date().getTime();
var latency = end - start;
responseFn(latency);
};
document.getElementsByTagName("head")[0].appendChild(script);
}
measureRemaining();
In this way, you'll get actual end-user performance from a (hopefully) large number of different network locations. You will probably want to do this in a separate iframe to avoid changing the behaviour of your webpage. |
|