Largest Contentful Paint (LCP)
npm@ using images from maxlg@
Objective
Measure how long the main content of the website takes to be rendered on screen
Which content is considered?
How is ‘main content’ determined?
We use largest element.
Pick the latest candidate found
LCP candidate 1
LCP candidate 2
Final LCP
When is LCP considered final?
We stop updating LCP when one of the following occurs:
Heuristics: removed elements
LCP uses some heuristics to ensure the algorithm chooses reasonable elements as the main content.
The most important one: the main content cannot be from a removed element.
Examples
Web Perf API for LCP?
Idea 1: provide ‘before_user_input’
Add a bit to Element Timing entries saying if the element rendered before any user input.
Idea 2: opting elements out
Allow developers to annotate that an element is NOT important, for example providing a specific keyword to elementtiming attribute.
Idea 3: Add ‘is_most_important’ bit
Whenever a new LCP candidate is found, dispatch an Element Timing entry with the ‘is_most_important’ bit set.
Idea 4: use a new entryType for LCP
Whenever a new LCP candidate is found, dispatch a new LCP entry.
Idea 5: Use the Reporting API
Expose LCP via the Reporting API.
Idea 6: add getMostImportantElement()
Allow developer to query the most important element via a method (in Performance). Encourage developers to use only when they find a new input, or on the onhidden callback.