/performance.js

calculate performance timing for web page

Primary LanguageJavaScript

Page Performance

1. Usage:

Install the performance.js file in the page, and listen to the perf event:

<script src="./performance.js"></script>
<script>
window.addEventListener('perf', function(perf) {
  console.log(perf.detail);
})
</script>

2. the perf.detail object

2.1 properties

lookupdns, domain lookup for the source
waitingnetwork latency, waiting before page request start
receivingperiod between request start and request end
parsingdom parsing, from dom loading to dom complete
contentLoadedwe used to call it dom ready
pageLoadedfrom user agent start a lookup to load event start

2.2 code to calculate out the properties

[ 'lookup'        , ['requestStart', 'navigationStart']],
[ 'waiting'       , ['responseStart', 'requestStart']],
[ 'receiving'     , ['responseEnd', 'responseStart']],
[ 'parsing'       , ['domComplete', 'domLoading']],
[ 'contentLoaded' , ['domContentLoadedEventStart', 'navigationStart']],
[ 'pageLoaded'    , ['loadEventStart', 'navigationStart']] 

2.3 performance life cycle chart

performance life cycle chart

3. Testcase

run the testcase.html file, please!

4. License

(c) MIT License