←back to thread

Critical CSS

(critical-css-extractor.kigo.studio)
234 points stevenpotts | 1 comments | | HN request time: 0s | source
Show context
lelandfe ◴[] No.43901905[source]
Nice one. Would be cool if this also handled responsiveness. The need to dedupe responsive critical styles has made me resort to manually editing all critical stylesheets I've ever made.

I also see that this brings in CSS variable definitions (sorry, ~custom properties~) and things like that. Since critical CSS's size matters so much, it might be worth giving an option to compile all of that down.

> Place your original non-critical CSS <link> tags just before the closing </body> tag

I don't recommend doing this: you still want the CSS downloaded urgently, critical CSS is a façade. Moving to the end of body means the good stuff is discovered late, and thus downloaded late (and will block render if the preloader[0] discovers it).

These days I'd recommend:

    <link rel="preload" href="styles.css" as="style" onload="this.rel='stylesheet'">

    <noscript><link rel="stylesheet" href="styles.css"></noscript>
[0] https://web.dev/articles/preload-scanner
replies(5): >>43903028 #>>43903093 #>>43904053 #>>43908668 #>>43928038 #
worble ◴[] No.43904053[source]

    <link rel="preload" href="styles.css" as="style" onload="this.rel='stylesheet'">
Wouldn't this be blocked by a CSP that doesn't allow unsafe-inline?
replies(2): >>43905381 #>>43905956 #
1. ◴[] No.43905381[source]