Is there a way I can get the load time of a URL or page from Jquery? For example, I make ajax request to "http://www.yahoo.com", I want to know how long it took to load the page completely. I am aware of the same domain policy. But I just want to write a simple javascript utility that can let me know page load time.
I know there are tools like YSlow etc, but I want this utility to be running continuously in browser tab and alert(javascript) alert when the page load time is beyond some threshold.
Thanks, J
Something like this should work nicely.
var startTime;
$.ajax({
// url, type, dataType, etc
beforeSend: function(xhr){
startTime = +new Date();
}
complete: function(xhr, state){
var latency = (+new Date()) - startTime;
window.console.log(latency);
}
});