8

I'm working on an upgrade for our current application (asp.net mvc). Here my problem is, I have a existing css file name "styles.css". Now this file has lots of css classes and they are used in different pages.

Now as a part of the upgrade process, this css file will not be used anymore. But I still want certain css classes from this file, so that I can copy them to a new file and include it in my pages.

Any ideas on how to extract these styles which are used in my new pages. And yes the styles which I want to pick are already set to the controls in the page. Please help.

Harsha
  • 1,161
  • 4
  • 18
  • 38
  • Possible duplicate of [Extracting only the css used in a specific page](http://stackoverflow.com/questions/4867005/extracting-only-the-css-used-in-a-specific-page) – thdoan Mar 07 '17 at 05:19

4 Answers4

10

Finding ones that are used in single page should be easy with multiple tools. One good tool is called UnCSS.

The trick is checking an entire site where CSS file is shared accross pages.

This approach was popular in social networks recently with some high profile guys sharing it like Google's Addy Osmani and some Google Chrome guys:

http://addyosmani.com/blog/removing-unused-css/

Meligy
  • 35,654
  • 11
  • 85
  • 109
6

Use Chrometools Audits

In Chrome Press: F12 -> Audits -> Run

It will let you know what is and is not used.

Chrome Audits

zero298
  • 25,467
  • 10
  • 75
  • 100
  • Is there a way to access this programmatically? – Gajus Jul 07 '17 at 18:18
  • @Gajus from what context? Do you mean as a browser extension or as an external website accessed by the client? I am somewhat hopeful that a website I access cannot run an audit on my machine without my permission. If from an extension context, I believe so. See: [chrome.experimental.devtools.audits](https://developer.chrome.com/extensions/experimental_devtools_audits) – zero298 Jul 07 '17 at 18:24
  • True. Website being able to run the audit could be a risk. I am primarily interested in the Chrome DevTools protocol, though. https://www.reddit.com/r/javascript/comments/6lvov7/how_to_use_the_chrome_devtools_protocol_to/ – Gajus Jul 07 '17 at 18:43
1

There are a lot of ways, for example:

Adel
  • 1,468
  • 15
  • 18
-1

Use a Browser Debugger, click on the elements on site and see on the right corner which classes are machtes and copy them.

alpham8
  • 1,314
  • 2
  • 14
  • 32