Css style

How to remove unused CSS from a heavy theme? – HTML & CSS – SitePoint Forums


I am using a very heavy theme on my wordpress cms and it has unsed css mentioned by Pagespeed insight.
Can you please help me remove unused CSS pages this time?

Are you sure that the styles not used on the tested page are not used anywhere else on the site.

I’ve seen tools check for unused CSS before, and the problem I saw with them was just that. They work on a single page in isolation. So if you had one CSS for the whole site, not everything CSS is mandatory on all page, while all of this can be used by the site as a whole.
That’s not to say you don’t have redundant CSS, but you would need to find a verification tool that sees the site as a whole.

1 like

I have experience with overzealous purists removing and cleaning up “unused” CSS without understanding the impact on other parts of the project. Removing “unused” CSS is not an easy thing to do without significant risk of breaking things for larger sites. Especially probably for a random theme retrieved from the Internet whose developer does not know the code. Unless the site is small or visual testing has been implemented in an automated way to detect visual breaks, this is a significant risk exercise.

1 like

There is a good article here this shows how difficult it can be and why you need to be extremely careful.