Network speed is quite different from webpage loading latency since the latter includes a multitude of other factors like server-side computational time, associated requests and caching, rendering, asynchronous elements, and so on.
In practice, the following solution will test the duration between when a GET request is sent off to the time when the response body has been completely received (but before anything is rendered or any associated assets are retrieved). I use the jQuery framework to simplify the XHR creation process somewhat, although you're free to use an alternative implementation.
// prepare the XHR object
$.ajax({
beforeSend: function(){
// right before firing off the request, create a global object that includes the request send time
window.startTime = new Date();
},
// send the request to the root URI of this host
url: '/',
success: function(){
// once the request comes back, record the end time
window.endTime = new Date();
// take the difference, which will yield a number in milliseconds, and print it out
document.write(window.endTime - window.startTime + " ms");
}
});
Source: http://jsfiddle.net/5h4GZ/
Just plop this in a <script>
tag on the page, and you're good to go. Modify the document.write
call as required to put it in a more conspicuous place. Also, feel free to insert a subsequent call there to your monitoring web service to write it to a database.
There are plenty of tutorials on geolocation online, so any one of those will do. You can capitalize on the Geolocation API, but more likely, you'll do fine just to do it by IP address, since that's actually more important for your needs. For this, there are plenty of web services online that will give you a geolocation based on IP. This can of course all be done server side, so the precise implementation will depend on your technologies.