3

A simple method to measure the roundtip-time of an Ajax request is to measure the time between the start and the end of a request (readyState 4). Many examples exist for this kind of measuring.

But this measurement is not really accurate. The Ajax callback will only be invoked, as soon as it comes up in the browser event loop. Which means that if there is some blocking operation inbetween, the measurement would also contain some client processing time and not the actual server roundtrip-time (server processing time + network time).

I know that this kind of functionality is now available through the Resource Timing API Specification, but at the moment it is not consistently implemented accross all browsers.

Is there any other way to find out the real roundtrip-time or the timestamp, at which the server response is available and waiting for the corresponding callback to execute?

ppa
  • 326
  • 1
  • 4
  • Reading your question, (I'm not familiar with the issue or the api you mention) I suspect not - otherwise what would be the benefit of introducing the Resource Timing API? – enhzflep Apr 16 '14 at 14:19

1 Answers1

1

NetworkInformation.rtt

You can use navigator.connection.rtt to obtain the estimated effective round-trip time of the current connection, rounded to the nearest multiple of 25 milliseconds.

const estimated_round_trip_time = navigator.connection.rtt;

console.log(estimated_round_trip_time);

Note: At the time of posting, navigator.connection.rtt is still considered experimental technology. Expect behavior to change in the future, and proceed with caution before using it in your application. See Browser Compatibility.

Grant Miller
  • 27,532
  • 16
  • 147
  • 165