Skip to content

Instantly share code, notes, and snippets.

@bgrins
Last active September 20, 2023 20:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrins/243b783921a30da94ad8deccceeb74c6 to your computer and use it in GitHub Desktop.
Save bgrins/243b783921a30da94ad8deccceeb74c6 to your computer and use it in GitHub Desktop.
-- https://github.com/HTTPArchive/almanac.httparchive.org/blob/a54cc07fc61461e1366112ba81cf6e8fed7236fa/sql/2022/css/multicol.sql#L9
-- https://github.com/HTTPArchive/almanac.httparchive.org/blob/a54cc07fc61461e1366112ba81cf6e8fed7236fa/sql/2021/css/grid_named_lines.sql#L9
CREATE TEMPORARY FUNCTION countMozImageRect(css STRING)
RETURNS NUMERIC
LANGUAGE js
OPTIONS (library = "gs://httparchive/lib/css-utils.js")
AS '''
try {
const ast = JSON.parse(css);
return countDeclarations(ast.stylesheet.rules, {values: /^-moz-image-rect/});
} catch (e) {
return false;
}
''';
SELECT
SUM(count_declarations) total_declarations,
COUNT(DISTINCT page) AS num_pages,
STRING_AGG(DISTINCT page, ', ') AS aggregated_urls
FROM (
SELECT
page,
SUM(countMozImageRect(css)) AS count_declarations
FROM
`httparchive.almanac.parsed_css`
WHERE
date = '2022-07-01'
AND client = "desktop"
AND countMozImageRect(css) > 0
GROUP BY
page
)
total_declarations num_pages aggregated_urls
7 4 "https://deshuniversal.com/, https://www.globaledulink.co.uk/, https://codebit.com.br/, https://manger.sortir-en-bretagne.fr/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment