Menu

551 CSS rules serve all 38 of our pages, and 39 of them match nothing anywhere
📰

551 CSS rules serve all 38 of our pages, and 39 of them match nothing anywhere

DEV Community: css·Daniel Pertu·6 days ago
#MynQYMyP
#devtocss#devto#dev#rules#pages
Long article (1275 words) — no AI summary yet.
Reading 0:00
15s threshold

Yesterday I ran V8 coverage over all 38 pages of notifio.app and found that a third of the JavaScript executes. The stylesheet is a much smaller problem, 8,348 bytes on the wire against 276,713 of JavaScript, so this is not a performance post. It turned into something more useful: a stylesheet built by a scanner is an index of everything the code could render, and diffing that against what the pages do render finds things no grep would.

The method, and the two traps in it

One request serves the whole site's CSS. Walk its rules, and for each selector ask the page how many elements it matches:

for ( const rule of sheet . cssRules ) { document . querySelectorAll ( rule . selectorText ) . length ; // plus a recursive walk into @layer, @media and @supports }

Enter fullscreen mode

Exit fullscreen mode

That naive version is wrong twice, and both traps flatter you.

State pseudo-classes. document.querySelectorAll('a:hover') is valid and returns zero, because nothing is hovered in a browser with no pointer.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.