Calculation of event latency load with window object.performance

Asked

Viewed 30 times

1

The time between the attribute window.performance.timing.connecStart and window.performance.timing.loadEventStart would be the time it took for the event window.onload was fired? I mean, from the connection to the callback of onload be executed?

I have the following function (it is part of a little lib of mine):

pageLoad: function() {
    var start, end, total;      
    start = window.performance.timing.connectStart;
    end = window.performance.timing.loadEventStart; 
    total = end - start;
    console.log(total + "ms para disparar o evento window.onload");
    return total;
} 

This function is accurately picking the connection interval up to the event window.onload be fired? If not, in what way could I do it?

  • From the MDN documentation it seems to be just that. There are some caveats about the value of connectStart when the connection is pre-established, but I don’t think it interferes with your logic.

1 answer

1


According to W3C recommendations about the object PerformanceTiming represented by window.performance.timing:

connectStart attribute

This attribute must Return the time immediately before the user agent start establishing the Connection to the server to Retrieve the Document. If a persistent Connection [RFC 2616] is used or the Current Document is retrieved from Relevant application caches or local Resources, this attribute must Return value of domainLookupEnd.

This attribute must return the time immediately before the user agent start trying to establish the connection to the server to receive the document in question. If there is a persistent connection [RFC 2616] or the document is received from the cache system or local resources, this attribute must return the value of domainLookupEnd.

loadEventStart attribute

This attribute must Return the time immediately before the load Event of the Current Document is Fired. It must Return zero when the load Event is not Fired yet.

This attribute must return the time immediately before the event load the current document is triggered. It must return zero while the event has not been triggered.

That is, considering that the first defines the time that the user agent establishes the connection to the server and the second time the event load will be fired, I believe it makes sense to define as latency (relative) of this same event the difference between these two values.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.