-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15c5656
commit 90c2064
Showing
2 changed files
with
34 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |