Load event latency calculation with window.performance object

1

Is the time between the attribute window.performance.timing.connecStart and window.performance.timing.loadEventStart the time it took for the window.onload event to fire? I mean, from the connection until the callback of onload is executed?

I have the following function (it's part of a small 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;
} 

Is this function accurately picking up the connection interval until the window.onload event is triggered? If not, how could I do this?

    
asked by anonymous 06.09.2017 / 13:32

1 answer

1

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

  

connectStart attribute

     

This attribute must return the time immediately before the user agent starting 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 should return the time immediately before the user agent starts attempting to connect to the server to receive the document in question. If a persistent connection exists [RFC 2616] or the document is received from the caching system or local resources, this attribute must return the value of domainLookupEnd .

  

loadEventStart attribute

     

This attribute must return the time immediately before the load of the current document is fired. It should return zero when the load event is not yet fired.

This attribute should return the time immediately before the load event of the current document is triggered. It should return zero as long as 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 the time the load event will be triggered, I believe it makes sense to define as (relative) latency of this same event the difference between these two values.

    
06.09.2017 / 14:14