by weinzierl · 2y ago · 0 comments
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.
I'd forgotten about it and am now wondering if anyone made a replacement...
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;