Closes #6527: Images intersecting viewport considered as lcp candidates #6549
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #6527
This PR modifies the
lcp-beacon.js
file to change the way the Largest Contentful Paint (LCP) is calculated. The changes include creating a new functionisIntersecting(rect)
that checks if an image is intersecting the viewport and modifying the area computation to account only for the visible part of the image.Documentation
User documentation
This change will improve the accuracy of the LCP calculation by considering images that intersect the viewport, not just those fully within it. This can lead to more accurate performance measurements and better user experience.
Technical documentation
The
isIntersecting(rect)
function checks if an image is intersecting the viewport by comparing the top and left properties of the image's bounding rectangle with the viewport's dimensions. The area computation is modified to calculate the visible area of the image by taking the minimum of the image's dimensions and the viewport's dimensions minus the image's position.Type of change
New dependencies
N/A
Risks
N/A
Checklists
Feature validation
Documentation
Code style