J.Doe J.Doe - 5 months ago 7x
Javascript Question

How to avail a multiple link latency check and show the ping result, then have the fastest URL picked out using JavaScript?

enter image description here

I've seem many websites having this function, and so as for the end user it's much easier to pick which URL or server has the best performance base on their location. I'm only a beginner in Javascript, can someone please show me how it's done?


You create a variable with the current time before the call (use an ajax call so you can keep the javascript variables, lost if the page is reloaded), then on the call success you again create a time variable and subtract it from the first. Possible dublicate of Find out how long an Ajax request took to complete

var start_time = new Date().getTime();

jQuery.get('your-url', data, 
    function(data, status, xhr) {
        var request_time = new Date().getTime() - start_time;