Last active
August 17, 2024 17:57
-
-
Save rviscomi/44d80c1a0f4dec9cbafb37347c770278 to your computer and use it in GitHub Desktop.
Exploration into the correlation between native image lazy loading and LCP performance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Distribution of LCP performance on WordPress pages across desktop/mobile with and without native image lazy loading. | |
SELECT | |
_TABLE_SUFFIX AS client, | |
percentile, | |
usesLazyLoading, | |
COUNT(0) AS pages, | |
COUNTIF(pctGoodLCP IS NOT NULL) AS pagesWithCrUXData, | |
APPROX_QUANTILES(pctGoodLCP, 1000)[OFFSET(percentile * 10)] AS pctGoodLCP, | |
APPROX_QUANTILES(p75LCP, 1000)[OFFSET(percentile * 10)] AS p75LCP | |
FROM ( | |
SELECT | |
_TABLE_SUFFIX, | |
url, | |
IF(IFNULL(REGEXP_CONTAINS(JSON_EXTRACT(payload, "$['_img-loading-attr']"), r'(?i)\blazy\b'), FALSE), 'Yes', 'No') AS usesLazyLoading, | |
JSON_QUERY(payload, "$._CrUX.metrics.largest_contentful_paint.histogram[0].density") AS pctGoodLCP, | |
JSON_QUERY(payload, "$._CrUX.metrics.largest_contentful_paint.percentiles.p75") AS p75LCP | |
FROM | |
`httparchive.pages.2021_06_01_*`) | |
JOIN ( | |
SELECT DISTINCT | |
_TABLE_SUFFIX, | |
url | |
FROM | |
`httparchive.technologies.2021_06_01_*` | |
WHERE | |
app = 'WordPress') | |
USING (url, _TABLE_SUFFIX), | |
UNNEST([10, 25, 50, 75, 90]) AS percentile | |
GROUP BY | |
client, | |
percentile, | |
usesLazyLoading | |
ORDER BY | |
client, | |
percentile, | |
usesLazyLoading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Distribution of LCP performance across desktop/mobile pages with and without native image lazy loading. | |
SELECT | |
_TABLE_SUFFIX AS client, | |
percentile, | |
usesLazyLoading, | |
COUNT(0) AS pages, | |
COUNTIF(pctGoodLCP IS NOT NULL) AS pagesWithCrUXData, | |
APPROX_QUANTILES(pctGoodLCP, 1000)[OFFSET(percentile * 10)] AS pctGoodLCP, | |
APPROX_QUANTILES(p75LCP, 1000)[OFFSET(percentile * 10)] AS p75LCP | |
FROM ( | |
SELECT | |
_TABLE_SUFFIX, | |
url, | |
IF(IFNULL(REGEXP_CONTAINS(JSON_EXTRACT(payload, "$['_img-loading-attr']"), r'(?i)\blazy\b'), FALSE), 'Yes', 'No') AS usesLazyLoading, | |
JSON_QUERY(payload, "$._CrUX.metrics.largest_contentful_paint.histogram[0].density") AS pctGoodLCP, | |
JSON_QUERY(payload, "$._CrUX.metrics.largest_contentful_paint.percentiles.p75") AS p75LCP | |
FROM | |
`httparchive.pages.2021_06_01_*`), | |
UNNEST([10, 25, 50, 75, 90]) AS percentile | |
GROUP BY | |
client, | |
percentile, | |
usesLazyLoading | |
ORDER BY | |
client, | |
percentile, | |
usesLazyLoading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Timeseries of lazy loading adoption on Wordpress, other CMSs, and non-CMS websites. | |
SELECT | |
CONCAT('202', REGEXP_REPLACE(SUBSTR(_TABLE_SUFFIX, 0, 7), r'_', r'-')) AS date, | |
IF(ENDS_WITH(_TABLE_SUFFIX, 'desktop'), 'desktop', 'mobile') AS client, | |
COUNT(0) AS total, | |
COUNTIF(NOT usesLazyLoading) AS notUsingLazyLoading, | |
COUNTIF(usesLazyLoading) AS usesLazyLoading, | |
COUNTIF(usesLazyLoading AND isWordPress) AS usesLazyLoadingWordPress, | |
COUNTIF(usesLazyLoading AND isCMS AND NOT isWordPress) AS usesLazyLoadingOtherCMS | |
FROM ( | |
SELECT | |
_TABLE_SUFFIX, | |
url, | |
IFNULL(REGEXP_CONTAINS(JSON_QUERY(payload, '$."_img-loading-attr"'), r'(?i)\blazy\b'), FALSE) AS usesLazyLoading | |
FROM | |
`httparchive.pages.202*`) | |
LEFT JOIN ( | |
SELECT | |
_TABLE_SUFFIX, | |
url, | |
COUNTIF(category = 'CMS') > 0 AS isCMS, | |
COUNTIF(app = 'WordPress') > 0 AS isWordPress | |
FROM | |
`httparchive.technologies.202*` | |
GROUP BY | |
1, 2) | |
USING (url, _TABLE_SUFFIX) | |
GROUP BY | |
date, | |
client | |
ORDER BY | |
date, | |
client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adoption of native image lazy loading broken down by WordPress, other CMSs, and non-CMS websites. | |
SELECT | |
_TABLE_SUFFIX AS client, | |
COUNTIF(usesLazyLoading AND isWordPress) / COUNTIF(usesLazyLoading) AS pctWordPressLazyLoading, | |
COUNTIF(usesLazyLoading AND isCMS AND NOT isWordPress) / COUNTIF(usesLazyLoading) AS pctOtherCMSLazyLoading, | |
COUNTIF(usesLazyLoading AND NOT isCMS) / COUNTIF(usesLazyLoading) AS pctNonCMSLazyLoading | |
FROM ( | |
SELECT | |
_TABLE_SUFFIX, | |
url, | |
IFNULL(REGEXP_CONTAINS(JSON_QUERY(payload, '$."_img-loading-attr"'), r'(?i)\blazy\b'), FALSE) AS usesLazyLoading | |
FROM | |
`httparchive.pages.2021_06_01_*`) | |
JOIN ( | |
SELECT | |
_TABLE_SUFFIX, | |
url, | |
COUNTIF(category = 'CMS') > 0 AS isCMS, | |
COUNTIF(app = 'WordPress') > 0 AS isWordPress | |
FROM | |
`httparchive.technologies.2021_06_01_*` | |
GROUP BY | |
1, 2) | |
USING (url, _TABLE_SUFFIX) | |
GROUP BY | |
client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Snippet to warn when the LCP element was lazy loaded. | |
new PerformanceObserver((entryList) => { | |
const entries = entryList.getEntries(); | |
const latestEntry = entries[entries.length - 1]; | |
if (latestEntry?.element?.getAttribute('loading') == 'lazy') { | |
console.warn('Warning: LCP element was lazy loaded', latestEntry); | |
} | |
}).observe({type: 'largest-contentful-paint', buffered: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results:
All pages:
WordPress: