-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathlcp_lazy_technologies.sql
More file actions
73 lines (68 loc) · 1.79 KB
/
lcp_lazy_technologies.sql
File metadata and controls
73 lines (68 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
CREATE TEMP FUNCTION isLazyLoaded(attributes STRING) RETURNS BOOLEAN LANGUAGE js AS '''
try {
const data = JSON.parse(attributes);
const loadingAttr = data.find(attr => attr["name"] === "loading")
return loadingAttr.value == 'lazy'
} catch (e) {
return null;
}
''';
CREATE TEMP FUNCTION hasLazyHeuristics(attributes STRING) RETURNS BOOLEAN LANGUAGE js AS '''
try {
const data = JSON.parse(attributes);
const classes = data.find(attr => attr["name"] === "class").value;
const hasLazyClasses = classes.indexOf('lazyload') !== -1;
const hasLazySrc = data.includes(attr => attr["name"] === "data-src");
return hasLazyClasses || hasLazySrc;
} catch (e) {
return false;
}
''';
WITH lazy_tech AS (
SELECT
client,
page,
isLazyLoaded(JSON_EXTRACT(custom_metrics, '$.performance.lcp_elem_stats.attributes')) AS native_lazy,
hasLazyHeuristics(JSON_EXTRACT(custom_metrics, '$.performance.lcp_elem_stats.attributes')) AS custom_lazy,
t.technology AS technology
FROM
`httparchive.all.pages`,
UNNEST(technologies) AS t
WHERE
date = '2023-10-01' AND
is_root_page
),
tech_totals AS (
SELECT
client,
technology,
COUNT(0) AS pages_per_technology
FROM
lazy_tech
GROUP BY
client,
technology
)
SELECT
client,
technology,
COUNTIF(native_lazy) AS native_lazy,
COUNTIF(custom_lazy) AS custom_lazy,
COUNTIF(native_lazy OR custom_lazy) AS either_lazy,
COUNT(0) AS pages,
COUNTIF(native_lazy) / COUNT(0) AS pct_native_lazy,
COUNTIF(custom_lazy) / COUNT(0) AS pct_custom_lazy,
COUNTIF(native_lazy OR custom_lazy) / COUNT(0) AS pct_either_lazy
FROM
lazy_tech
JOIN
tech_totals
USING (client, technology)
GROUP BY
client,
technology
HAVING
pages > 1000 AND
pct_either_lazy > 0.1
ORDER BY
either_lazy DESC