Skip to content

Commit 531412b

Browse files
NishuGoelpankajparkarmax-ostapenkodependabot[bot]tunetheweb
authored
JavaScript 2021 chapter and query updates (#2567)
* add requests, async, module queries * Added ajax request per page percentile based query. * Added most requested content-types. * Formatted query. * Added query for iframe per page. * Percentage usage of different ajax APIs. * Added h1 vs h2 vs h3 script. * Added web_components_sepc sql. * linting * consistent syntax to count number of rows * frameworks, sourcemaps queries * 1p vs 3p * adds unminified, preload/prefetch queries * PR feedback accomodate & fixes * link fix * Feedback II update * Fixed review comment related to web_component_specs. * update content_type and webcomponent query * Javascript sql 2021 (#2386) * Bump prettier from 2.4.0 to 2.4.1 in /src (#2334) Bumps [prettier](https://github.com/prettier/prettier) from 2.4.0 to 2.4.1. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](prettier/prettier@2.4.0...2.4.1) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Turn off uses-passive-event-listeners Lighthouse audit (#2335) * Bump node-watch from 0.7.1 to 0.7.2 in /src (#2336) Bumps [node-watch](https://github.com/yuanchuan/node-watch) from 0.7.1 to 0.7.2. - [Release notes](https://github.com/yuanchuan/node-watch/releases) - [Changelog](https://github.com/yuanchuan/node-watch/blob/master/Changelog.md) - [Commits](yuanchuan/node-watch@0.7.1...v0.7.2) --- updated-dependencies: - dependency-name: node-watch dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * PWA 2021 queries (#2272) * Initial conversion of queries to custom metrics * Better Lighthouse queries * Remove comma * Add Service Worker over time for top 1k sites query * Change adoption ranking to include all ranking categories * Formatting * Linting fixes * Spacing improvements * Missing queries * Query updates * Missed some * Remove s * Space * Misc updates * More Tweaks * Spacing fixes * Fix assestlinks query * Missing DESC * Group rankings properly * Linting fixes * Remove unnecessary extra join * Spacing * Additional queries * Linting fixes * Update Events to look at onEvents * Better array merge * Misc fixes * Better JS * Filtering false positives for install query * Fixes to events query * Adding comment for install query * Expand on comment * Review feedback * Linting fixes * Correct comment * Apply suggestions from code review Co-authored-by: David Fox <david@davidjfox.com> * Review feedback * Review feedback * Change to COUNT(DISTINCT url) Co-authored-by: demianrenzulli <demian77@gmail.com> Co-authored-by: David Fox <david@davidjfox.com> * Bump sqlfluff from 0.6.5 to 0.6.6 in /src (#2339) Bumps [sqlfluff](https://github.com/sqlfluff/sqlfluff) from 0.6.5 to 0.6.6. - [Release notes](https://github.com/sqlfluff/sqlfluff/releases) - [Changelog](https://github.com/sqlfluff/sqlfluff/blob/main/CHANGELOG.md) - [Commits](sqlfluff/sqlfluff@0.6.5...0.6.6) --- updated-dependencies: - dependency-name: sqlfluff dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add more 2 more PWA queries (#2340) * Small SQL linting fixes to old media queries (#2341) * Caching 2021 queries (#2254) * Update README.md * Top CDNs * caching queries part 1 * LH queries * caching sql part 2 * changes from review * comment * Delete sql/2021/third-parties directory (#2342) * Delete sql/2021/third-parties directory * Delete third-parties.md * frameworks, sourcemaps queries * 1p vs 3p * adds unminified, preload/prefetch queries * Bump actions/github-script from 4.1 to 5 (#2346) Bumps [actions/github-script](https://github.com/actions/github-script) from 4.1 to 5. - [Release notes](https://github.com/actions/github-script/releases) - [Commits](actions/github-script@v4.1...v5) --- updated-dependencies: - dependency-name: actions/github-script dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/setup-node from 2.4.0 to 2.4.1 (#2347) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.4.0 to 2.4.1. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](actions/setup-node@v2.4.0...v2.4.1) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump github/super-linter from 4.7.3 to 4.8.0 (#2350) * Bump github/super-linter from 4.7.3 to 4.8.0 Bumps [github/super-linter](https://github.com/github/super-linter) from 4.7.3 to 4.8.0. - [Release notes](https://github.com/github/super-linter/releases) - [Changelog](https://github.com/github/super-linter/blob/master/docs/release-process.md) - [Commits](github/super-linter@v4.7.3...v4.8.0) --- updated-dependencies: - dependency-name: github/super-linter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Fix queries failing linting Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Barry <barry@tunetheweb.com> * PR feedback accomodate & fixes * link fix * Feedback II update * Fixed review comment related to web_component_specs. * update content_type and webcomponent query Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Barry Pollard <barry_pollard@hotmail.com> Co-authored-by: demianrenzulli <demian77@gmail.com> Co-authored-by: David Fox <david@davidjfox.com> Co-authored-by: Rick Viscomi <rviscomi@users.noreply.github.com> Co-authored-by: Barry <barry@tunetheweb.com> Co-authored-by: Pankaj Parkar <parkarpankaj3@gmail.com> * lint fixes * lint fix -2 * add review updates * add trailing newline * update queries & markdown init * update SQL queries * lint fixes * lint fixes trailing whitespace * update SQL file names * Apply suggestions from code review * update module_and_nomodule * chapter markdown update * Apply suggestions from code review * Update src/content/en/2021/javascript.md * add NishuGoel_bio * add relevant links, edit * incorporate reviews/edits * add description for figures * fixes & edits * Fix tables * Fix spacing * Fix headings * Smart quotes * Remove unnecessary tables * Fix links * Fix headings and rearrange content * Further reordering * More clean up * Add images * More edits * update on TODO items from @tunetheweb Co-authored-by: Pankaj Parkar <parkarpankaj3@gmail.com> Co-authored-by: Max Ostapenko <bvz2001@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Barry Pollard <barry_pollard@hotmail.com> Co-authored-by: demianrenzulli <demian77@gmail.com> Co-authored-by: David Fox <david@davidjfox.com> Co-authored-by: Rick Viscomi <rviscomi@users.noreply.github.com> Co-authored-by: Barry <barry@tunetheweb.com>
1 parent 4f5241a commit 531412b

37 files changed

+1074
-11
lines changed

sql/2021/javascript/ajax_async.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# standardSQL
2+
# usage of async XMLHttpRequest using blink features from usage counters
3+
SELECT
4+
client,
5+
pct_urls
6+
FROM
7+
`httparchive.blink_features.usage`
8+
WHERE
9+
yyyymmdd = '20210701' AND
10+
feature = 'XMLHttpRequestAsynchronous'
11+
GROUP BY
12+
pct_urls,
13+
client
14+
ORDER BY
15+
pct_urls,
16+
client

sql/2021/javascript/ajax_request_per_page.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# standardSQL
2+
# breadkdown of asynchronous JavaScript and XML requests per page
13
SELECT
24
client,
35
percentile,

sql/2021/javascript/ajax_sync.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# standardSQL
2+
# usage of synchronous XMLHttpRequest using blink features from usage counters
3+
SELECT
4+
client,
5+
pct_urls
6+
FROM
7+
`httparchive.blink_features.usage`
8+
WHERE
9+
yyyymmdd = '20210701' AND
10+
feature = 'XMLHttpRequestSynchronous'
11+
GROUP BY
12+
pct_urls,
13+
client
14+
ORDER BY
15+
pct_urls,
16+
client
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#standardSQL
2+
# Breakdown of scripts using Async, Defer, Module or NoModule attributes. Also breakdown of inline vs external scripts
3+
SELECT
4+
_TABLE_SUFFIX AS client,
5+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async') AS INT64) > 0) AS async,
6+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.defer') AS INT64) > 0) AS defer,
7+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async_and_defer') AS INT64) > 0) AS async_and_defer,
8+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.type_module') AS INT64) > 0) AS module,
9+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.nomodule') AS INT64) > 0) AS nomodule,
10+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async') AS INT64) > 0) / COUNT(0) AS async_pct,
11+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.defer') AS INT64) > 0) / COUNT(0) AS defer_pct,
12+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.async_and_defer') AS INT64) > 0) / COUNT(0) AS async_and_defer_pct,
13+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.type_module') AS INT64) > 0) / COUNT(0) AS module_pct,
14+
COUNTIF(CAST(JSON_EXTRACT(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.script_tags.nomodule') AS INT64) > 0) / COUNT(0) AS nomodule_pct,
15+
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,
16+
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
17+
FROM
18+
`httparchive.pages.2021_07_01_*`
19+
GROUP BY
20+
client
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#standardSQL
2+
# Breakdown of scripts using Async, Defer, Module or NoModule attributes. Also breakdown of inline vs external scripts
3+
CREATE TEMPORARY FUNCTION getScripts(payload STRING)
4+
RETURNS STRUCT<total INT64, inline INT64, src INT64, async INT64, defer INT64, async_and_defer INT64, type_module INT64, nomodule INT64>
5+
LANGUAGE js AS '''
6+
try {
7+
var $ = JSON.parse(payload);
8+
var javascript = JSON.parse($._javascript);
9+
return javascript.script_tags;
10+
} catch (e) {
11+
return {};
12+
}
13+
''';
14+
15+
SELECT
16+
client,
17+
SUM(script.total) AS total_scripts,
18+
SUM(script.inline) AS inline_script,
19+
SUM(script.src) AS external_script,
20+
SUM(script.src) / SUM(script.total) AS pct_external_script,
21+
SUM(script.inline) / SUM(script.total) AS pct_inline_script,
22+
SUM(script.async) AS async,
23+
SUM(script.defer) AS defer,
24+
SUM(script.async_and_defer) AS async_and_defer,
25+
SUM(script.type_module) AS module,
26+
SUM(script.nomodule) AS nomodule,
27+
SUM(script.async) / SUM(script.src) AS pct_external_async,
28+
SUM(script.defer) / SUM(script.src) AS pct_external_defer,
29+
SUM(script.async_and_defer) / SUM(script.src) AS pct_external_async_defer,
30+
SUM(script.type_module) / SUM(script.src) AS pct_external_module,
31+
SUM(script.nomodule) / SUM(script.src) AS pct_external_nomodule
32+
FROM (
33+
SELECT
34+
_TABLE_SUFFIX AS client,
35+
getScripts(payload) AS script
36+
FROM
37+
`httparchive.pages.2021_07_01_*`)
38+
GROUP BY
39+
client
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#standardSQL
2+
# Pages with vulnerable libraries
3+
SELECT
4+
score,
5+
COUNT(0) AS pages,
6+
SUM(COUNT(0)) OVER () AS total,
7+
COUNT(0) / SUM(COUNT(0)) OVER () AS pct
8+
FROM (
9+
SELECT
10+
JSON_EXTRACT_SCALAR(report, "$.audits['no-vulnerable-libraries'].score") AS score
11+
FROM
12+
`httparchive.lighthouse.2021_07_01_mobile`)
13+
WHERE
14+
score IS NOT NULL
15+
GROUP BY
16+
score
17+
ORDER BY
18+
score
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#standardSQL
2+
# Most frequent vulnerable libraries
3+
CREATE TEMPORARY FUNCTION getVulnerabilities(audit STRING)
4+
RETURNS ARRAY<STRING> LANGUAGE js AS '''
5+
try {
6+
var $ = JSON.parse(audit);
7+
return $.details.items.map(i => i.detectedLib.text.split('@')[0]);
8+
} catch(e) {
9+
return [];
10+
}
11+
''';
12+
13+
SELECT
14+
lib,
15+
COUNT(0) AS freq,
16+
total,
17+
COUNT(0) / total AS pct
18+
FROM
19+
`httparchive.lighthouse.2021_07_01_mobile`,
20+
UNNEST(getVulnerabilities(JSON_EXTRACT(report, "$.audits['no-vulnerable-libraries']"))) AS lib, (
21+
SELECT
22+
COUNT(DISTINCT url) AS total
23+
FROM
24+
`httparchive.lighthouse.2021_07_01_mobile`)
25+
GROUP BY
26+
lib,
27+
total
28+
ORDER BY
29+
freq DESC
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SELECT
2+
client,
3+
COUNT(DISTINCT IF(module, page, NULL)) AS module,
4+
COUNT(DISTINCT IF(nomodule, page, NULL)) AS nomodule,
5+
COUNT(DISTINCT IF(nomodule AND module, page, NULL)) AS both,
6+
COUNT(DISTINCT page) AS total,
7+
COUNT(DISTINCT IF(module, page, NULL)) / COUNT(DISTINCT page) AS pct_module,
8+
COUNT(DISTINCT IF(nomodule, page, NULL)) / COUNT(DISTINCT page) AS pct_nomodule,
9+
COUNT(DISTINCT IF(module AND nomodule, page, NULL)) / COUNT(DISTINCT page) AS pct_both
10+
FROM (
11+
SELECT
12+
client,
13+
page,
14+
script,
15+
REGEXP_CONTAINS(script, r'(?i)\bmodule\b') AS module,
16+
REGEXP_CONTAINS(script, r'(?i)\bnomodule\b') AS nomodule
17+
FROM
18+
`httparchive.almanac.summary_response_bodies`
19+
LEFT JOIN
20+
UNNEST(REGEXP_EXTRACT_ALL(body, r'(?i)(<script[^>]*>)')) AS script
21+
WHERE
22+
date = '2021-07-01' AND
23+
firstHtml)
24+
GROUP BY
25+
client
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#standardSQL
2+
# Distribution of 1P/3P JS requests
3+
SELECT
4+
percentile,
5+
client,
6+
host,
7+
APPROX_QUANTILES(requests, 1000)[OFFSET(percentile * 10)] AS num_requests
8+
FROM (
9+
SELECT
10+
client,
11+
page,
12+
IF(NET.HOST(url) IN (
13+
SELECT domain FROM `httparchive.almanac.third_parties` WHERE date = '2021-07-01' AND category != 'hosting'
14+
), 'third party', 'first party') AS host,
15+
COUNT(0) AS requests
16+
FROM
17+
`httparchive.almanac.requests`
18+
WHERE
19+
date = '2021-07-01' AND
20+
type = 'script'
21+
GROUP BY
22+
client,
23+
page,
24+
host),
25+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
26+
GROUP BY
27+
percentile,
28+
client,
29+
host
30+
ORDER BY
31+
percentile,
32+
client,
33+
host

sql/2021/javascript/web_components_specs.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ FROM (
1111
ARRAY_LENGTH(JSON_EXTRACT_ARRAY(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.web_component_specs.shadow_roots')) AS shadow_roots,
1212
ARRAY_LENGTH(JSON_EXTRACT_ARRAY(JSON_EXTRACT_SCALAR(payload, '$._javascript'), '$.web_component_specs.template')) AS template
1313
FROM
14+
# Note: We're intentionally querying the September dataset here because of a bug in the custom metric.
15+
# See https://github.com/HTTPArchive/legacy.httparchive.org/pull/231.
1416
`httparchive.pages.2021_09_01_*`),
1517
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
1618
GROUP BY

0 commit comments

Comments
 (0)