Skip to content

Commit

Permalink
Add more queries
Browse files Browse the repository at this point in the history
  • Loading branch information
khempenius committed Jul 27, 2020
1 parent 15c5656 commit 90c2064
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 47 deletions.
58 changes: 11 additions & 47 deletions sql/2020/21_Resource_Hints/21_05.sql
Original file line number Diff line number Diff line change
@@ -1,50 +1,14 @@
#standardSQL
# 21_05: Preload only: % of sites that are using as=font/as=fetch without a crossorigin attribute,
# or that are using any other as value with a crossorigin attribute.
CREATE TEMPORARY FUNCTION getResourceHints(payload STRING)
RETURNS ARRAY<STRUCT<name STRING, href STRING>>
LANGUAGE js AS '''
var hints = new Set(['preload', 'prefetch']);
try {
var $ = JSON.parse(payload);
var almanac = JSON.parse($._almanac);
return almanac['link-nodes'].reduce((results, link) => {
var hint = link.rel.toLowerCase();
if (!hints.has(hint)) {
return results;
}
results.push({
name: hint,
href: link.href
});
return results;
}, []);
} catch (e) {
return [];
}
''';

# 21_05: Usage of Guess.js
SELECT
_TABLE_SUFFIX AS client,
name,
type,
COUNT(0) AS freq,
SUM(COUNT(0)) OVER (PARTITION BY _TABLE_SUFFIX, name) AS total,
ROUND(COUNT(0) * 100 / SUM(COUNT(0)) OVER (PARTITION BY _TABLE_SUFFIX, name), 2) AS pct
FROM (
SELECT _TABLE_SUFFIX, url AS page, hint.name, hint.href AS url
FROM `httparchive.almanac.pages`, UNNEST(getResourceHints(payload)) AS hint)
LEFT JOIN (
SELECT client AS _TABLE_SUFFIX, page, url, type
FROM `httparchive.almanac.summary_requests`
WHERE edition = "2020")
USING
(_TABLE_SUFFIX, page, url)
client,
COUNT(0) AS total,
COUNTIF(REGEXP_CONTAINS(body, r'__GUESS__')) AS guess,
FROM
`httparchive.almanac.summary_response_bodies`
WHERE
type = "script"
AND
edition = "2020"
GROUP BY
client,
name,
type
ORDER BY
freq DESC
client
23 changes: 23 additions & 0 deletions sql/2020/21_Resource_Hints/21_06.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#standardSQL
# 21_06: Frequency of link tags that set both preconnect & dns-prefetch
CREATE TEMPORARY FUNCTION getResourceHints(payload STRING)
RETURNS BOOLEAN
LANGUAGE js AS '''
try {
var $ = JSON.parse(payload);
var almanac = JSON.parse($._almanac);
return !!almanac['link-nodes'].find((node) => {
var rel = node.rel.toLowerCase();
return rel.includes("preconnect") && rel.includes("dns-prefetch");
});
} catch (e) {
return false;
}
''';
SELECT
COUNTIF(getResourceHints(payload)) AS freq,
COUNT(0) AS total
FROM
`httparchive.almanac.pages`
WHERE
edition = "2020"

0 comments on commit 90c2064

Please sign in to comment.