Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find unused CSS rule and js script in a web project?

HI.. My project has many CSS roles and JavaScript scripts that are not used in my project. How can I find these unused files?

like image 575
M.Azad Avatar asked Jun 02 '11 08:06

M.Azad


People also ask

How do I get unused CSS rules?

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.

Where is unused CSS and JS file in WordPress?

On the post edit screen, you'll find the Asset CleanUp box just below the post editor. The plugin will automatically fetch and list all the files and assets loaded when a visitor views this page on your website. You can then simply unload the unused CSS or JavaScript files that you don't need on that page.


1 Answers

There is a nice little firefox plugin called Dust Me Selectors, which scans a page for CSS which isn't being used.

It's a very good tool for spotting things in your stylesheets which are redundant.

However, you still need to be careful with it, as it is quite possible for a stylesheet to be unused when you run the program, but still necessary for your site - ie it could be used for dynamic content, or for other pages which share the same stylesheet code, etc.

[EDIT]

I've removed my previous edit where I noted that this project might have been abandoned, because in fact it looks like it's back in active development. Good news all round.

like image 118
Spudley Avatar answered Oct 12 '22 21:10

Spudley