Thanks for your post, it gave me an idea. I remember this write up on inserting code into Go to do tracing, the code was called GoWeave https://github.com/deferpanic/goweave
My thought was, what if we used something like SASS to generate the css. We then automatically inserted some type of numbered 1 pixel gif background image rules into each aspect of the SASS, ran the page though some automated browser/mobile tests, had the server record formatted logs for these 1 pixel gifs, then finally created a detailed report that had the mapping of 1 pixel gifs back to the sass/css aspect.
Re:Ask HN: How do you find unused CSS?
by seanwilson on Tuesday March 22, 2016 @05:30PM
(#11340098)
> Ideally what you need is some tool that you start, use the site, then stop and it marks any CSS it didn't "see" used throughout that time. But I don't know of such a tool.
You can probably make a tool which works 90% of the time but it's an unsolvable problem to completely automate given the dynamic nature of web and JavaScript code.
So you can load a page, get all of the unused selectors, removed said selectors, and then have your entire site break. Why? Because dynamic elements don't exist in the DOM and people have per site CSS rather than per page CSS.
Ideally what you need is some tool that you start, use the site, then stop and it marks any CSS it didn't "see" used throughout that time. But I don't know of such a tool.
Sorry if this isn't super helpful. I am more just saying "I have looked, never found anything."