Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danBamikiya
Forked from addyosmani/custom-metrics.js
Created May 10, 2021 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danBamikiya/dc02a903ff93eb7bac1a26a89db6732c to your computer and use it in GitHub Desktop.
Save danBamikiya/dc02a903ff93eb7bac1a26a89db6732c to your computer and use it in GitHub Desktop.
custom-metrics.js
[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