Remove erroneous check for resource initiator type when considering whether to submit LCP background image #1760
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.
Summary
When setting up a demo site with Optimization Detective, I was confused when I wasn't getting the
lcpElementExternalBackgroundImage
data submitted with the URL Metric. In looking at the console, I saw:This was strange because the LCP element was definitely using a
background-image
coming from a stylesheet:Nevertheless, the
initiatorType
of the resource was coming through as animg
and not ascss
. Then I looked further down the page and I found the same image was being used in anIMG
tag:This actually reveals an interesting performance fact: even though the image is being used as a background image for the LCP element, there is an image way further down the page which is actually initiating the loading of this image before the stylesheet is initiating the load. Even more surprising, this
IMG
hasloading=lazy
. This highlights the need for adding a preload link for this image URL so that it is properly prioritized!Granted, it may be unlikely for the exact same image used as the LCP element's background to also appear further down the page in non-example content. In any case, checking the
initiatorType
for the resource was redundant because it's already aborting if the LCP element is anIMG
tag:performance/plugins/image-prioritizer/detect.js
Lines 90 to 98 in 2033d44
Therefore, there is no need for the additional check.