Network speed is very different from the latency of loading a web page, since the latter includes many other factors, such as server-side computing time, related requests and caching, rendering, asynchronous elements, etc.
In practice, the following solution will check the duration between when the GET request is sent at the time the response body was fully received (but before anything is displayed or any related assets are retrieved). I use the jQuery framework to simplify the process of creating XHR, although you can use an alternative implementation.
$.ajax({
beforeSend: function(){
window.startTime = new Date();
},
url: '/',
success: function(){
window.endTime = new Date();
document.write(window.endTime - window.startTime + " ms");
}
});
Source: http://jsfiddle.net/5h4GZ/
<script> , . document.write , . , - , .
- , . API , , , , IP-, . - , IP. , , .