ct.css Turns the Document Head Into a Performance Diagnostic

Harry's ct.css is a piece of CSS trickery that surfaces generic performance advice by inspecting what sits inside a page's <head> element.

The mechanism starts with a known quirk: a <style> block becomes visible like any other element once its display is changed away from the default none. The same trick works on elements placed in the <head>.

head,
head style,
head script {
  display: block;
}

The clever part is the selectors. Harry derives problematic situations from where certain tags are used and where they land in the document. Take a <script> that appears after some styles:

<head>
  <link rel="stylesheet" href="...">
  <script src="..."></script>
  <title>Page Title</title>
  <!-- ...  -->

That is bad, since the script is blocked by CSS, likely unnecessarily. Sophisticated performance tooling could report this — and so can a CSS selector:

head [rel="stylesheet"]:not([media="print"]):not(.ct) ~ script,
head style:not(:empty) ~ script {

}

Roughly it behaves like head link ~ script, but with extra precision: it matches only genuine stylesheets or style blocks that actually block, excluding itself. Styling and pseudo-content are then attached to those blocks, which turns the stylesheet into a visual debugging tool for performance.

The stylesheet covers plenty of small checks — unneeded attributes, blocking resources, elements in the wrong order.