Skip to content
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

JavaScript Queries for 2024 #3735

Merged
merged 53 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1647eb8
initial commit
nrllh Aug 15, 2024
6947541
JavaScript Queries for 2024
nrllh Aug 16, 2024
f468716
bytes_by_3p.sql fixed
nrllh Aug 16, 2024
27a0bb6
Update breakdown_of_pages_using_async_defer.sql
mgifford Aug 26, 2024
46b3ccf
Update breakdown_of_scripts_using_async_defer_module_nomodule.sql
mgifford Aug 26, 2024
044b2fc
Update distribution_of_injected_scripts.sql
mgifford Aug 26, 2024
bf99589
Update distribution_of_long_tasks_time.sql
mgifford Aug 26, 2024
1a22470
Update injected_scripts.sql
mgifford Aug 26, 2024
416aa4f
Update percent_of_dns_prefetch.sql
mgifford Aug 26, 2024
12c9dd3
Update percent_of_preconnect_by_host.sql
mgifford Aug 26, 2024
7fbce85
Update render_blocking_javascript.sql
mgifford Aug 26, 2024
d3da1b3
Update render_blocking_javascript_by_rank.sql
mgifford Aug 26, 2024
75e1a9d
Update resource-hints-prefetch-preload-modulepreload-percentage.sql
mgifford Aug 26, 2024
ac1fb96
Update resource-hints-preload-prefetch-modulepreload-distribution.sql
mgifford Aug 26, 2024
87fa25d
Update resource_hints.sql
mgifford Aug 26, 2024
c61e746
Update resource_hints_per_page.sql
mgifford Aug 26, 2024
03e11d3
Update sourcemaps.sql
mgifford Aug 26, 2024
a79bf12
Update usage_of_typescript_and_babel.sql
mgifford Aug 26, 2024
e7a585d
Update web_components_is_attribute.sql
mgifford Aug 26, 2024
42907b1
Update web_components_pct.sql
mgifford Aug 26, 2024
85de9f7
Update breakdown_of_pages_using_async_defer.sql
mgifford Aug 26, 2024
6718cea
Update breakdown_of_scripts_using_async_defer_module_nomodule.sql
mgifford Aug 26, 2024
b1441ad
Update resource-hints-prefetch-preload-modulepreload-percentage.sql
mgifford Aug 26, 2024
1118923
Update resource-hints-preload-prefetch-modulepreload-distribution.sql
mgifford Aug 26, 2024
17f86f3
Update resource_hints.sql
mgifford Aug 26, 2024
27a7ce2
Update breakdown_of_pages_using_async_defer.sql
mgifford Aug 26, 2024
2cc80b4
Update bytes_by_3p.sql
mgifford Aug 26, 2024
0c40db8
Update distribution_of_injected_scripts.sql
mgifford Aug 26, 2024
90db4ad
Update distribution_of_long_tasks_time.sql
mgifford Aug 26, 2024
de4fef7
Update distribution_of_number_of_long_tasks.sql
mgifford Aug 26, 2024
6c3fce8
Update frameworks_libraries_by_version.sql
mgifford Aug 26, 2024
e52da82
Update injected_scripts.sql
mgifford Aug 26, 2024
39885e6
Update module_and_nomodule.sql
mgifford Aug 26, 2024
2cb6ddd
Update percent_of_dns_prefetch.sql
mgifford Aug 26, 2024
bdecf7f
Update percent_of_dns_prefetch_by_host.sql
mgifford Aug 26, 2024
dff6ab3
Update percent_of_preconnect_by_host.sql
mgifford Aug 26, 2024
5438910
Update render_blocking_javascript.sql
mgifford Aug 26, 2024
edb7e4d
Update render_blocking_javascript_by_rank.sql
mgifford Aug 26, 2024
70c651b
Update resource-hints-prefetch-preload-modulepreload-percentage.sql
mgifford Aug 26, 2024
c9626e3
Update resource-hints-preload-prefetch-modulepreload-distribution.sql
mgifford Aug 26, 2024
ea46dcd
Update resource_hints.sql
mgifford Aug 26, 2024
2bf3a75
Update resource_hints_per_page.sql
mgifford Aug 26, 2024
263643e
Update sourcemaps.sql
mgifford Aug 26, 2024
194d1ea
Update usage_of_typescript_and_babel.sql
mgifford Aug 26, 2024
ac0d77f
Update web_components_is_attribute.sql
mgifford Aug 26, 2024
09cbeac
Update web_components_pct.sql
mgifford Aug 26, 2024
42e4e44
Update web_components_specs.sql
mgifford Aug 26, 2024
6be0c5d
Update module_and_nomodule.sql
mgifford Aug 26, 2024
8917eb0
Update distribution_of_number_of_long_tasks.sql
mgifford Aug 26, 2024
e286b80
Update distribution_of_long_tasks_time.sql
mgifford Aug 26, 2024
5c0883f
Update frameworks_libraries_by_version.sql
mgifford Aug 26, 2024
d5825fe
Update module_and_nomodule.sql
mgifford Aug 26, 2024
e44448f
Update bytes_by_3p.sql
mgifford Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sql/2024/javascript/breakdown_of_pages_using_async_defer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#standardSQL
# Breakdown of scripts using Async, Defer, Module or NoModule attributes. Also breakdown of inline vs external scripts
SELECT
_TABLE_SUFFIX AS client,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async') AS INT64) > 0) AS async,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.defer') AS INT64) > 0) AS defer,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async_and_defer') AS INT64) > 0) AS async_and_defer,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.type_module') AS INT64) > 0) AS module,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.nomodule') AS INT64) > 0) AS nomodule,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async') AS INT64) > 0) / COUNT(0) AS async_pct,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.defer') AS INT64) > 0) / COUNT(0) AS defer_pct,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async_and_defer') AS INT64) > 0) / COUNT(0) AS async_and_defer_pct,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.type_module') AS INT64) > 0) / COUNT(0) AS module_pct,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.nomodule') AS INT64) > 0) / COUNT(0) AS nomodule_pct,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async') AS INT64) = 0 AND CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.defer') AS INT64) = 0) AS neither,
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async') AS INT64) = 0 AND CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.defer') AS INT64) = 0) / COUNT(0) AS neither_pct
FROM
`httparchive.all.pages`
WHERE
date = '2024-06-01'

GROUP BY
client
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#standardSQL
# Breakdown of scripts using Async, Defer, Module or NoModule attributes. Also breakdown of inline vs external scripts
CREATE TEMPORARY FUNCTION getScripts(payload STRING) RETURNS STRUCT < total INT64,
inline INT64,
src INT64,
async INT64,
defer INT64,
async_and_defer INT64,
type_module INT64,
nomodule INT64 > LANGUAGE js AS '''
try {
var $ = JSON.parse(payload);
var javascript = JSON.parse($._javascript);
return javascript.script_tags;
} catch (e) {
return {};
}
''';

SELECT
client,
SUM(script.total) AS total_scripts,
SUM(script.inline) AS inline_script,
SUM(script.src) AS external_script,
SUM(script.src) / SUM(script.total) AS pct_external_script,
SUM(script.inline) / SUM(script.total) AS pct_inline_script,
SUM(script.async) AS async,
SUM(script.defer) AS defer,
SUM(script.async_and_defer) AS async_and_defer,
SUM(script.type_module) AS module,
SUM(script.nomodule) AS nomodule,
SUM(script.async) / SUM(script.src) AS pct_external_async,
SUM(script.defer) / SUM(script.src) AS pct_external_defer,
SUM(script.async_and_defer) / SUM(script.src) AS pct_external_async_defer,
SUM(script.type_module) / SUM(script.src) AS pct_external_module,
SUM(script.nomodule) / SUM(script.src) AS pct_external_nomodule
FROM
(
SELECT
client,
getScripts(payload) AS script
FROM
`httparchive.all.pages`
WHERE
date = '2024-06-01'
)
GROUP BY
client
15 changes: 15 additions & 0 deletions sql/2024/javascript/bytes_2019.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#standardSQL
# Sum of JS request bytes per page (2019)
SELECT
percentile,
_TABLE_SUFFIX AS client,
APPROX_QUANTILES(bytesJs / 1024, 1000)[OFFSET(percentile * 10)] AS js_kilobytes
FROM
`httparchive.summary_pages.2019_07_01_*`,
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
GROUP BY
percentile,
client
ORDER BY
client,
percentile
15 changes: 15 additions & 0 deletions sql/2024/javascript/bytes_2020.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#standardSQL
# Sum of JS request bytes per page (2020)
SELECT
percentile,
_TABLE_SUFFIX AS client,
APPROX_QUANTILES(bytesJs / 1024, 1000)[OFFSET(percentile * 10)] AS js_kilobytes
FROM
`httparchive.summary_pages.2020_08_01_*`,
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
GROUP BY
percentile,
client
ORDER BY
client,
percentile
15 changes: 15 additions & 0 deletions sql/2024/javascript/bytes_2021.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#standardSQL
# Sum of JS request bytes per page (2021)
SELECT
percentile,
_TABLE_SUFFIX AS client,
APPROX_QUANTILES(bytesJs / 1024, 1000)[OFFSET(percentile * 10)] AS js_kilobytes
FROM
`httparchive.summary_pages.2021_07_01_*`,
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
GROUP BY
percentile,
client
ORDER BY
client,
percentile
15 changes: 15 additions & 0 deletions sql/2024/javascript/bytes_2022.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#standardSQL
# Sum of JS request bytes per page (2022)
SELECT
percentile,
_TABLE_SUFFIX AS client,
APPROX_QUANTILES(bytesJs / 1024, 1000)[OFFSET(percentile * 10)] AS js_kilobytes
FROM
`httparchive.summary_pages.2022_06_01_*`,
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
GROUP BY
percentile,
client
ORDER BY
client,
percentile
15 changes: 15 additions & 0 deletions sql/2024/javascript/bytes_2023.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#standardSQL
# Sum of JS request bytes per page (2023)
SELECT
percentile,
_TABLE_SUFFIX AS client,
APPROX_QUANTILES(bytesJs / 1024, 1000)[OFFSET(percentile * 10)] AS js_kilobytes
FROM
`httparchive.summary_pages.2023_06_01_*`,
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
GROUP BY
percentile,
client
ORDER BY
client,
percentile
15 changes: 15 additions & 0 deletions sql/2024/javascript/bytes_2024.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#standardSQL
# Sum of JS request bytes per page (2024)
SELECT
percentile,
_TABLE_SUFFIX AS client,
APPROX_QUANTILES(bytesJs / 1024, 1000)[OFFSET(percentile * 10)] AS js_kilobytes
FROM
`httparchive.summary_pages.2024_06_01_*`,
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
GROUP BY
percentile,
client
ORDER BY
client,
percentile
34 changes: 34 additions & 0 deletions sql/2024/javascript/bytes_by_3p.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#standardSQL
# Distribution of 1P/3P JS bytes
SELECT
percentile,
client,
host,
APPROX_QUANTILES(kbytes, 1000)[OFFSET(percentile * 10)] AS kbytes
FROM (
SELECT
client,
page,
IF(NET.HOST(url) IN (
SELECT domain FROM `httparchive.almanac.third_parties` WHERE date = '2024-06-01' AND category != 'hosting'
), 'third party', 'first party') AS host,
SUM(cast(json_value(payload, '$.response.bodySize') AS INT64)) / 1024 AS kbytes
FROM
`httparchive.all.requests`

WHERE
date = '2024-06-01' AND
type = 'script'
GROUP BY
client,
page,
host),
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
GROUP BY
percentile,
client,
host
ORDER BY
client,
percentile,
host
47 changes: 47 additions & 0 deletions sql/2024/javascript/compression_method.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#standardSQL
CREATE TEMPORARY FUNCTION getHeader(headers STRING, headername STRING)
RETURNS STRING
DETERMINISTIC
LANGUAGE js AS '''
const parsed_headers = JSON.parse(headers);
const matching_headers = parsed_headers.filter(h => h.name.toLowerCase() == headername.toLowerCase());
if (matching_headers.length > 0) {
return matching_headers[0].value;
}
return null;
''';

SELECT
client,
compression,
COUNT(DISTINCT page) AS pages,
ANY_VALUE(total_pages) AS total_pages,
COUNT(DISTINCT page) / ANY_VALUE(total_pages) AS pct_pages,
COUNT(0) AS js_requests,
SUM(COUNT(0)) OVER (PARTITION BY client) AS total_js_requests,
COUNT(0) / SUM(COUNT(0)) OVER (PARTITION BY client) AS pct_js_requests
FROM (
SELECT
client,
page,
getHeader(JSON_EXTRACT(payload, '$.response.headers'), 'Content-Encoding') AS compression
FROM
`httparchive.all.requests`
WHERE
date = '2024-06-01' AND
type = 'script')
JOIN (
SELECT
_TABLE_SUFFIX AS client,
COUNT(0) AS total_pages
FROM
`httparchive.summary_pages.2024_06_01_*`
GROUP BY
client)
USING
(client)
GROUP BY
client,
compression
ORDER BY
pct_js_requests DESC
52 changes: 52 additions & 0 deletions sql/2024/javascript/compression_method_by_3p.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#standardSQL
CREATE TEMPORARY FUNCTION getHeader(headers STRING, headername STRING)
RETURNS STRING
DETERMINISTIC
LANGUAGE js AS '''
const parsed_headers = JSON.parse(headers);
const matching_headers = parsed_headers.filter(h => h.name.toLowerCase() == headername.toLowerCase());
if (matching_headers.length > 0) {
return matching_headers[0].value;
}
return null;
''';

SELECT
client,
host,
compression,
COUNT(DISTINCT page) AS pages,
ANY_VALUE(total_pages) AS total_pages,
COUNT(DISTINCT page) / ANY_VALUE(total_pages) AS pct_pages,
COUNT(0) AS js_requests,
SUM(COUNT(0)) OVER (PARTITION BY client, host) AS total,
COUNT(0) / SUM(COUNT(0)) OVER (PARTITION BY client, host) AS pct
FROM (
SELECT
client,
page,
IF(NET.HOST(url) IN (
SELECT domain FROM `httparchive.almanac.third_parties` WHERE date = '2024-06-01' AND category != 'hosting'
), 'third party', 'first party') AS host,
getHeader(JSON_EXTRACT(payload, '$.response.headers'), 'Content-Encoding') AS compression
FROM
`httparchive.all.requests`
WHERE
date = '2024-06-01' AND
type = 'script')
JOIN (
SELECT
_TABLE_SUFFIX AS client,
COUNT(0) AS total_pages
FROM
`httparchive.summary_pages.2024_06_01_*`
GROUP BY
client)
USING
(client)
GROUP BY
client,
host,
compression
ORDER BY
pct DESC
55 changes: 55 additions & 0 deletions sql/2024/javascript/compression_none_by_bytes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#standardSQL
CREATE TEMPORARY FUNCTION getHeader(headers STRING, headername STRING)
RETURNS STRING
DETERMINISTIC
LANGUAGE js AS '''
const parsed_headers = JSON.parse(headers);
const matching_headers = parsed_headers.filter(h => h.name.toLowerCase() == headername.toLowerCase());
if (matching_headers.length > 0) {
return matching_headers[0].value;
}
return null;
''';

SELECT
client,
host,
IF(kbytes < 100, FLOOR(kbytes / 5) * 5, 100) AS kbytes,
COUNT(DISTINCT page) AS pages,
ANY_VALUE(total_pages) AS total_pages,
COUNT(DISTINCT page) / ANY_VALUE(total_pages) AS pct_pages,
COUNT(0) AS js_requests,
SUM(COUNT(0)) OVER (PARTITION BY client, host) AS total,
COUNT(0) / SUM(COUNT(0)) OVER (PARTITION BY client, host) AS pct
FROM (
SELECT
client,
page,
IF(NET.HOST(url) IN (
SELECT domain FROM `httparchive.almanac.third_parties` WHERE date = '2024-06-01' AND category != 'hosting'
), 'third party', 'first party') AS host,
respSize / 1024 AS kbytes
FROM
`httparchive.all.requests`
WHERE
date = '2024-06-01' AND
type = 'script' AND
getHeader(JSON_EXTRACT(payload, '$.response.headers'), 'Content-Encoding') IS NULL)
JOIN (
SELECT
_TABLE_SUFFIX AS client,
COUNT(0) AS total_pages
FROM
`httparchive.summary_pages.2024_06_01_*`
GROUP BY
client)
USING
(client)
GROUP BY
client,
host,
kbytes
ORDER BY
client,
host,
kbytes
Loading