CSSnano
cssnano.github.io
cssnano.github.io
=> Users with low bandwidth and/or flakey connection benefit
Happy to learn otherwise though!
Edit: I mean, in the real world. Obviously in their example gzip does pretty much nothing since there's so little content, which leave very little room for compression.
So maybe another thirty percent, probably from removing comments etc, not just whitespace.
2. CSS often blocks page render, to avoid flashing unstyled content.
3. "Tree-shaking" CSS is often difficult or impossible.
Many (most?) CSS libraries minify their outputs...Bootstrap, Materialize, Semantic UI, Foundation.
I've had great results since. No more unused CSS. No more minifying nor bundling. What you write is what you get. It's liberating! Hehe.
What I have in mind is a tool that I throw a CSS file and a bunch of static HTML files at, it will try to apply each CSS rule to the HTML like a browser would and remove all the rules that don't apply.
I don't expect it to ascertain if a rule had visible effects. I also don't expect it to consider JavaScript. Just plain CSS and static HTML. It doesn't look to me like CSSnano or LighteningCSS could do that.
The AMP WordPress plugin also does something like this IIRC (to try and fit stylesheets into AMP's size limit) but the tooling for it might be written in PHP.
Above is a nice online version of Purify. But it just seems to minimize the CSS, and doesn’t delete the unused CSS.
the only thing that does not work is generating the css class like:
var x = 'hase-';
var t = x + 'danger'
which is an antipattern. (it can even happen inside java, c#, whatever language you use and it is still an antipattern)
switch(buttonColor) {
'red': return 'button-red';
'blue': return 'button-blue';
}
over return 'button-' + buttonColor;I'd forgotten about it and am now wondering if anyone made a replacement...
Here's a more complete result adding brotli and the aforementioned cpp version:
$ gdu -b *.css *.css.gz *.css.br | awk '{if (NR % 3 == 1) {ref = $1; print} else print $0, "(" $1 - ref ")"}'
623 in.css
197 out.css (-426)
355 out_cpp.css (-268)
345 in.css.gz
185 out.css.gz (-160)
235 out_cpp.css.gz (-110)
284 in.css.br
141 out.css.br (-143)
177 out_cpp.css.br (-107)I do find that CSSO[1] with structural optimizations can be more effective still, perhaps that will be less true overtime though.
I think once lightning CSS is more stable (in particular, some bugs are addressed around ordering) it will be the clear winner in this space though.
Whether that is measurable is a different story :)