From 8ca1031bd81b73fbcb859f5be6be3a12500ebde9 Mon Sep 17 00:00:00 2001 From: Nishu Goel Date: Tue, 31 Aug 2021 01:56:52 +0530 Subject: [PATCH 01/23] add requests, async, module queries --- sql/2021/javascript/async_and_defer.sql | 25 +++++++++++++ ...ipts_using_async_defer_module_nomodule.sql | 36 +++++++++++++++++++ ...ipts_using_async_defer_module_nomodule.sql | 34 ++++++++++++++++++ sql/2021/javascript/requests_2019.sql | 16 +++++++++ sql/2021/javascript/requests_2020.sql | 15 ++++++++ sql/2021/javascript/requests_2021.sql | 16 +++++++++ 6 files changed, 142 insertions(+) create mode 100644 sql/2021/javascript/async_and_defer.sql create mode 100644 sql/2021/javascript/avg_pct_per_page_scripts_using_async_defer_module_nomodule.sql create mode 100644 sql/2021/javascript/breakdown_of_scripts_using_async_defer_module_nomodule.sql create mode 100644 sql/2021/javascript/requests_2019.sql create mode 100644 sql/2021/javascript/requests_2020.sql create mode 100644 sql/2021/javascript/requests_2021.sql diff --git a/sql/2021/javascript/async_and_defer.sql b/sql/2021/javascript/async_and_defer.sql new file mode 100644 index 00000000000..718e7201bd8 --- /dev/null +++ b/sql/2021/javascript/async_and_defer.sql @@ -0,0 +1,25 @@ +SELECT + client, + COUNT(DISTINCT IF(async, page, NULL)) AS async, + COUNT(DISTINCT IF(defer, page, NULL)) AS defer, + COUNT(DISTINCT IF(async AND defer, page, NULL)) AS both, + COUNT(DISTINCT page) AS total, + COUNT(DISTINCT IF(async, page, NULL)) / COUNT(DISTINCT page) AS pct_async, + COUNT(DISTINCT IF(defer, page, NULL)) / COUNT(DISTINCT page) AS pct_defer, + COUNT(DISTINCT IF(async AND defer, page, NULL)) / COUNT(DISTINCT page) AS pct_both +FROM ( + SELECT + client, + page, + script, + REGEXP_CONTAINS(script, r'(?i)\basync\b') AS async, + REGEXP_CONTAINS(script, r'(?i)\bdefer\b') AS defer + FROM + `httparchive.sample_data.summary_response_bodies` -- TODO: update to the original table name + LEFT JOIN + UNNEST(REGEXP_EXTRACT_ALL(body, r'(?i)(]*>)')) AS script + WHERE + date = '2021-08-01' AND + firstHtml) +GROUP BY + client diff --git a/sql/2021/javascript/avg_pct_per_page_scripts_using_async_defer_module_nomodule.sql b/sql/2021/javascript/avg_pct_per_page_scripts_using_async_defer_module_nomodule.sql new file mode 100644 index 00000000000..1e06046cf91 --- /dev/null +++ b/sql/2021/javascript/avg_pct_per_page_scripts_using_async_defer_module_nomodule.sql @@ -0,0 +1,36 @@ +#standardSQL +# Average Percent per page of external scripts using Async, Defer, Module or NoModule attributes. +SELECT + client, + AVG(pct_external_async) AS avg_pct_external_async, + AVG(pct_external_defer) AS avg_pct_external_defer, + AVG(pct_external_module) AS avg_pct_external_module, + AVG(pct_external_nomodule) AS avg_pct_external_nomodule +FROM ( + SELECT + client, + page, + COUNT(0) AS external_scripts, + COUNTIF(REGEXP_CONTAINS(script, r'\basync\b')) / COUNT(0) AS pct_external_async, + COUNTIF(REGEXP_CONTAINS(script, r'\bdefer\b')) / COUNT(0) AS pct_external_defer, + COUNTIF(REGEXP_CONTAINS(script, r'\bmodule\b')) / COUNT(0) AS pct_external_module, + COUNTIF(REGEXP_CONTAINS(script, r'\bnomodule\b')) / COUNT(0) AS pct_external_nomodule + FROM ( + SELECT + client, + page, + url, + REGEXP_EXTRACT_ALL(body, "(?i)(