0

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?

J.Doe
  • 3
  • 2

1 Answers1

0

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;
    }
);
Community
  • 1
  • 1
Velimir Tchatchevsky
  • 2,812
  • 1
  • 16
  • 21
  • 1
    even if the response is "*you can't talk to me*", you know how long it takes to get a response. – Kaiido May 14 '16 at 11:13