Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing unused CSS from website code

I am currently modifying a website template which I have found for free on the web.

When i remove, for instance, a div from the code, the CSS for it remains behind, in one or more files.

Is there a tool which automatically removes unused CSS from my code? So i don't manually search for every id and class that i don't use anymore and remove the code.

like image 361
AndreiBogdan Avatar asked Aug 23 '12 12:08

AndreiBogdan


People also ask

How do I find unused CSS in HTML?

The Coverage tab in Chrome DevTools can help you find unused JavaScript and CSS code. Removing unused code can speed up your page load and save your mobile users cellular data.

How do I know which CSS is not used?

1. Audit Tab: > Right Click + Inspect Element on the page, find the "Audit" tab, and run the audit, making sure "Web Page Performance" is checked. Lists all unused CSS tags - see image below.


2 Answers

Intellij IDEA can do this. Navigate to CSS file, click on 'Analyze' and then reduce the analysis scope to a selected file. After that you will be presented with all problems related to this file. All errors are divided into categories, navigate to the category named 'Unused CSS selector' to find what you're after. The same should work for JavaScript. Please note that CSS support is only available in Ultimate version of IDEA, though it's totally worth every buck you spend on it. There is also a 30-day trial period for Ultimate edition. Oh, and by the way it has an excellent PHP support. There is also a cheaper PHP-specific IDE from the same vendor called PHPStorm. Analysis features are also available there.

like image 90
NewlessClubie Avatar answered Sep 18 '22 07:09

NewlessClubie


You can get pretty close to what you are asking for with the Google Chrome's Audit tab under Developer Tools. It does not remove unused CSS, but it will show you what CSS rules are not being used.

Observe: enter image description here

like image 21
shanabus Avatar answered Sep 18 '22 07:09

shanabus