Created
April 3, 2020 16:49
-
-
Save addyosmani/554ba464e5d32b66620f55e583b2c0fd to your computer and use it in GitHub Desktop.
custom-metrics.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[lcp] | |
const po = new PerformanceObserver(() => {}); | |
po.observe({type: 'largest-contentful-paint', buffered: true}); | |
const lastEntry = po.takeRecords().slice(-1)[0]; | |
return lastEntry.renderTime || lastEntry.loadTime; | |
[cls] | |
const po = new PerformanceObserver(() => {}); | |
po.observe({type: 'layout-shift', buffered: true}); | |
return po.takeRecords().reduce((val, entry) => val + entry.value, 0); | |
[fid] | |
const po = new PerformanceObserver(() => {}); | |
po.observe({type: 'first-input', buffered: true}); | |
const lastEntry = po.takeRecords().slice(-1)[0]; | |
return lastEntry.processingStart - lastEntry.startTime; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment