Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created April 9, 2024 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/0cc169156302d3012f1cfdfb06ab32fc to your computer and use it in GitHub Desktop.
Save westonruter/0cc169156302d3012f1cfdfb06ab32fc to your computer and use it in GitHub Desktop.
# HTTP Archive query for how often the mediaelement-core script is on a WordPress page.
#
# WPP Research, Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
CREATE TEMP FUNCTION HAS_SCRIPT(handle STRING, custom_metrics STRING) RETURNS BOOL LANGUAGE js AS
# language=javascript
'''
/**
* Get whether a script is present.
*
* @param {string} handle
* @param {object} data
* @param {object} data.cms
* @param {object} data.cms.wordpress
* @param {Array<{handle: string}>} data.cms.wordpress.scripts
* @return {boolean}
*/
function hasScript(handle, data) {
for (const script of data.cms.wordpress.scripts) {
if (script.handle === handle) {
return true;
}
}
return false;
}
try {
const data = JSON.parse(custom_metrics);
return hasScript(handle, data);
} catch (e) {}
return false;
''';
WITH script_presence AS (
SELECT
HAS_SCRIPT("mediaelement-core", custom_metrics) AS has_script,
FROM
`httparchive.all.pages`,
UNNEST(technologies) AS technology
WHERE
date = CAST("2024-03-01" AS DATE) AND
client = "mobile" AND
technology.technology = "WordPress"
)
SELECT
has_script,
COUNT(has_script) AS count,
FROM
script_presence
GROUP BY
has_script
@westonruter
Copy link
Author

Results:

has_script count
false 10453165
true 512069

So the MediaElement.js script is present on 4.7% of WordPress pages. Note this will not identify ME.js on pages that that have optimization plugins which concatenate scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment