As an example, let’s find out how many sites are still using
document.write in their JS.
We’ll start writing our query to use the
httparchive:har.latest_lighthouse_mobile table, which automatically matches the most recent results as new crawls complete. Since the data is in JSON format, we’ll use
JSON_EXTRACT_SCALAR to pluck out a piece of data using its address in the JSON object. So for this particular audit score, the address is:
$ represents the root of the JSON object and each dot-notation property is a deeper level in the object.
So here’s the full query to get a breakdown of scores for this particular audit:
SELECT JSON_EXTRACT_SCALAR(report, "$.audits.no-document-write.score") AS score, COUNT(0) AS volume FROM [httparchive:har.latest_lighthouse_mobile] WHERE report IS NOT NULL GROUP BY score HAVING score IS NOT NULL ORDER BY score
The results are split pretty evenly:
score volume false 213456 true 214479
So about half of the pages crawled by HTTP Archive are still using
document.write. The best part of it all is that we get to watch these metrics update every couple of weeks and monitor how the web is changing.
Feel free to comment in this thread if you’ve got any other interesting findings from the Lighthouse data.