-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add query to determine frequency of the same image being LCP between desktop & mobile #73
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter The query mostly looks good so far, but there is one notable issue with it: As far as I can tell, relying on the fetchpriority
attribute here is an unnecessary limitation that drastically reduces the dataset we can work with. I'm not sure why we need to use fetchpriority
in this query in the first place.
Rather than using fetchpriority
to determine whether a site has an image as the LCP element on both mobile and desktop (which could in principle also have false positives if both images are different but both have the same fetchpriority
attribute applied), I would advise that we make this dependent on a more reliable approach - for example by comparing the src
(or if we want to be very verbose, the entire tag's attributes). Instead of getAttr()
, you could have a function like hasSameAttributes()
. This would then cover way more WordPress sites.
I think we should remove the limitation to WordPress 6.3 as well, since this question isn't really specific to whether or not fetchpriority
is applied.
@westonruter Other than my query review feedback above, two questions on your summary in the PR description:
Can you clarify where that percentage comes from?
I'm not sure I understand what you mean. Why can't we discover whether a page has the same LCP image on mobile and desktop regardless of |
Unfortunately, I found that we cannot compare the We could potentially see if there is a CSS selector exposed in the Lighthouse LCP audit and compare that, but there could still be some variance based on the time of crawling (e.g. differing class names).
Yeah, from the results there are 44,601 pages that correctly set Update: I updated the description to fix my faulty calculation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @westonruter, LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the merge conflict now
The current PHP heuristics adds
fetchpriority=high
to the same image for both desktop and mobile clients. Nevertheless, some sites serve different assets for desktop and mobile via CSS media queries. In such cases, when the LCP image on desktop is givenfetchpriority=high
, it can be that for mobile that the LCP image lacksfetchpriority=high
and also getsloading=lazy
. This PR seeks to determine how common a scenario this is.At present, it is only considering cases in which
fetchpriority=high
was added correctly to the LCP image for either the desktop or the mobile. If so, then it counts how often or not both desktop and mobile havefetchpriority=high
on the LCP image. It is also only considering mobile and desktop pages which both have an image as the LCP element. Lastly, it only considers WordPress 6.3.x since this is the version in whichfetchpriority
was introduced.(Query elapsed time: 11 min 38 sec)
Of the matching pages, ~63% (25,860/70,461) have the same image as LCP for desktop and mobile. (Or technically that both of these images have
fetchpriority=high
, which WordPress only adds to one image.) So there is ~37% headroom here to improve LCP detection.Note that this does not account for the case when
fetchpriority=high
is missing on both the LCP image for desktop and mobile. To account for this, we would not be able to rely onlcp_elem_stats
orraw_lcp_element
since they lack sufficient information:JSON
In order to expand the set of URLs beyond ~70K, we would need to query for the LCP element on desktop and mobile, and then compare the image attributes or the CSS selectors as is exposed by the Lighthouse audit. However, this is complicated by the fact that the desktop and mobile crawls by HTTP Archive may reflect different states of the page, such as when a new article is published and appears at the top of the homepage between desktop and mobile crawls. When this happens, the
src
of the LCP elements will no longer match so they cannot be compared, and the selectors could involve some attachment ID or post ID, so they may not be reliable to compare either.