Created
May 23, 2020 11:19
-
-
Save tunetheweb/55dc5be4be4e48d85925cb583c35e14d to your computer and use it in GitHub Desktop.
Percent of pages that include link[rel=alternate] for stylesheets
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
#standardSQL | |
# Percent of pages that include link[rel=alternate] for stylesheets | |
# Warning this uses 500GB of BigQuery usage so can be expensive to run multiple times! | |
CREATE TEMP FUNCTION hasAlternateCSS(payload STRING) | |
RETURNS BOOLEAN LANGUAGE js AS ''' | |
try { | |
var $ = JSON.parse(payload); | |
var almanac = JSON.parse($._almanac); | |
return !!almanac['link-nodes'].find( | |
e => e.rel.toLowerCase().includes('alternate') | |
&& | |
( | |
e.as.toLowerCase() == 'style' || e.href.toLowerCase().includes('.css') || e.type.toLowerCase() == 'text/css' | |
) | |
); | |
} catch (e) { | |
return false; | |
} | |
'''; | |
SELECT | |
_TABLE_SUFFIX AS client, | |
COUNTIF(hasAlternateCSS(payload)) AS num_pages, | |
COUNT(0) AS total, | |
ROUND(COUNTIF(hasAlternateCSS(payload)) * 100 / COUNT(0), 2) AS pct_alternate_css | |
FROM | |
`httparchive.pages.2020_05_01_*` | |
GROUP BY | |
client |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results as of 1st May 2020: