This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

Performance

Summary

Provides methods for performance timing.

Properties

onresourcetimingbufferfull
This callback is triggered when the buffer used to store the list of PerformanceResourceTiming is full.

Methods

clearResourceTimings
Clears the buffer used to store the current list of PerformanceResourceTiming resources.
setResourceTimingBufferSize
Sets the maximum number of PerformanceResourceTiming resources that may be stored in the buffer to the value of the maxSize parameter.

Events

No events.

Examples

The following script calculates the amount of time it takes to fetch every resource in the page, even those defined in markup:

<!doctype html>
<html>
  <head>
  </head>
  <body onload="loadResources()">
    <script>
       function loadResources()
       {
          var image1 = new Image();
          image1.src = 'http://w3c-test.org/webperf/image1.png';
          image1.onload = resourceTiming;
       }

       function resourceTiming()
       {
           var resourceList = window.performance.getEntriesByType("resource");
           for (i = 0; i < resourceList.length; i++)
           {
              if (resourceList[i].initiatorType == "img")
              {
                 alert("End to end resource fetch: "+ resourceList[i].responseEnd - resourceList[i].startTime);
              }
           }
       }
    </script>
    <img id="image0" src="http://w3c-test.org/webperf/image0.png">
  </body>
</html>

Related specifications

W3C Resource Timing Specification
W3C Candidate Recommendation

Attributions