News for hackers. Stuff that matters.
Re:Tools for Auditing CSS by cjpearson on Thursday April 01, 2021 @09:47PM (#26668352)
I've struggled with this as well. As far as I can tell there isn't a good solution, but I'd love to be proven wrong.

You can run PurgeCSS in a dry mode to find any unused selectors, but it can't handle any classes that are dynamically generated. If your codebase has used anything like `buttonClass = 'button-' + color`, you may get false positives.

The Chrome Dev Tools coverage can show you how much of a stylesheet is used at runtime, but if you concat everything into a single css file that's used for every page, a single page's usage doesn't help.

Re:Tools for Auditing CSS by DrOctagon on Thursday April 01, 2021 @11:25PM (#26668773)
Re:Tools for Auditing CSS by cjpearson on Friday April 02, 2021 @07:49AM (#26670647)
Yeah, I do like working with Tailwind and PurgeCSS and that setup works great. It's a good way of avoiding the unused CSS problem in the first place.

The problem for me is digging into a large existing codebase which has built up thousands of semantic class names and a bunch of nesting in the CSS. I'd like a tool that could tell me what's probably not being used, which I could then use as a starting point for some clean up.