Measuring server response time (client-side)

Kraken picture Kraken · Feb 13, 2013 · Viewed 27.2k times · Source

I would like to implement a script that would measure the response time of my server (= remote url) from a client using a regular browser without any extra plugins (Java etc.).

I'm only looking at the network speed (response time), not the page loading speed.

What would you recommend me to measure? It has to run on tcp/ip, not anything else like ICMP (ping).

How would you go around the implementation on the client side? I would prefer to use JavaScript (JQuery).


Update: As I need a cross domain check, the ajax calls don't seem to be an option

Furthermore, the ajax method doesn't seem to precise at all. Results seem to have an overhead of about 50ms (it's almost a constant value, no matter what the domain is - I guess it's the processing time in between) on the testing machine in comparison to information from FireBug

Answer

Robert Fricke picture Robert Fricke · Feb 13, 2013

You just need to time a request:

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

$.ajax({
    //type: "GET", //with response body
    type: "HEAD", //only headers
    url: "/someurl.htm",
    success: function(){

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

        var responseTimeMs = receiveDate - sendDate;

    }
});