Important metrics to measure

LCP

  1. new PerformanceObserver((entryList) => {
  2. for (const entry of entryList.getEntries()) {
  3. console.log('LCP candidate:', entry.startTime, entry);
  4. }
  5. }).observe({type: 'largest-contentful-paint', buffered: true});

Metrics - 图1

web-vitals

https://github.com/GoogleChrome/web-vitals

  1. import {getLCP, getFID, getCLS} from 'web-vitals';
  2. getCLS(console.log);
  3. getFID(console.log);
  4. getLCP(console.log);

TTI

image.png

FID

First input delay

image.png

  1. new PerformanceObserver((entryList) => {
  2. for (const entry of entryList.getEntries()) {
  3. const delay = entry.processingStart - entry.startTime;
  4. console.log('FID candidate:', delay, entry);
  5. }
  6. }).observe({type: 'first-input', buffered: true});