npressfetimg-1638.png

How to remove unused CSS from heavy theme? – SitePoint

CSS

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.


SamA74

June 16, 2022, 7:40pm
#3

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

SamA74:

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.

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


PaulOB

June 17, 2022, 4:00pm
#6

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

2 Likes

Source: https://www.sitepoint.com/community/t/how-to-remove-unused-css-from-heavy-theme/388965

RSS Feeds

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

npressfetimg-294.png
CSS

The art of pure CSS | BCS – BCS

For you Be part of something bigger, join the Chartered Institute for IT. Personally, discovering that browser capability early on in my coding career was a game-changing moment. The browser inspector is, to me, the closest thing we have to making abstract code feel real and tangible. Being able to click a chunk of code