Hacker News new | past | comments | ask | show | jobs | submit login

Particularly hard to fix for a site that's been around a while. It's difficult to identify dead css because you would have to have something like 100% DOM test coverage.

Perhaps that "dead" style is only used for that error div that isn't visible unless some rare condition exists.




The solution to this is to treat CSS as a unit of code, like Javascript and before static analysis on the result.

Solutions like CSS Modules and Styled Components are getting _really_ really close. CSS Modules lets you do this at a component level, and is theoretically possible to do it at an individual class level (providing you use a 'safe' syntax).


PurifyCSS does that: https://github.com/purifycss/purifycss

The only issue I have come across is when you are inserting elements with CSS classes using JavaScript. A workaround for this is importing the CSS in the JS module you are using it in via webpack or PurifyCSS also has an option to manually exclude certain selectors.


As you mention, It does if you somehow click every combination of buttons, invoke every error, corner case, etc. It can't know about HTML that isn't there, but could be.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: