How to remove unused CSS from heavy theme?

Hey!

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

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

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

1 Like

I have experience with over zealous purists that remove and cleanup “unused” css without understanding the impact on other parts of the project. Removing “unused” css isn’t a easy thing to do without significant risk of breaking things for larger sites. Especially probably so for a random theme grabbed off the internet which the developer is not familiar with the code. Unless the site is small or visual testing has been implemented in automated fashion to detect visual breaks its an exercise not without significant risk.

1 Like

There’s a good article here that shows how hard this can be and why you have to be ultra careful.

2 Likes