Jump to content

Remove Unused CSS

Go to solution Solved by alpenwasser,

I was able to install cssselect, lxml, and setuptools from these links, but I'm not sure if they were the correct one's I was supposed to install.

Yeah I think those are the right ones.

I have made a small tutorial and put it into a separate thread so that it's easier to expand

and edit later on should that become necessary. Let me know if it does or does not work for you.

Cheers,

-aw

I was wondering how to remove unused CSS rules. I made a website using Twitter Bootstrap so I used some of their CSS rules as well as some of my own. I added all the files to one huge CSS file so my HTML only needs to call for 1 CSS file instead of like 5. I also made the huge file all into 1 line and removed any white space to make it as efficient as possible. So my question is, how can I compare the CSS file with my HTML file and have it remove any unused css that is not needed for that page?

 

I have tried Unused-CSS but you need a paid account in order to download the clean css file.

I was having a look at mincss but I have no-idea on how to use it. I tried looking up YouTube videos about it but all that came up was some Counter-Strike Videos.

  • CPU:  Intel 3770k @ 4.4 GHz
  • Motherboard:  MSI Z77A-G45 
  • RAM:  16GB Corsair Vengeance 2133Mhz
  • Graphics:  EVGA GTX 970
  • PSU: Corsair AX850
  • Cooling:  Corsair H100i
  • Case: Fractal Design Define R5
  • Keyboard: Corsair STRAFE Cherry MX Red
  • Mouse: Razer DeathAdder
  • Headphones: Corsair Vengeance 1400
  • Monitor: BenQ XL2420TE 24" 1ms 144Hz

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/
Share on other sites

Link to post
Share on other sites

Do you primarily need to find out which rules are unused (which you can

do in Chrome and most likely also Firefox' debugging tool suite) or do

you actually want to put in your old file and get back a cleaned-up new

version? As said, the former can be done with a browser's integrated

debugging tools, but since I've always done my CSS by hand I've never

used an automated tool, so I don't know a lot about the latter.

I have heard some good things about mincss, if you really want this

I recommend looking around for some tutorials and working yourself through

the docs.

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-867388
Share on other sites

Link to post
Share on other sites

Do you primarily need to find out which rules are unused (which you can

do in Chrome and most likely also Firefox' debugging tool suite) or do

you actually want to put in your old file and get back a cleaned-up new

version? As said, the former can be done with a browser's integrated

debugging tools, but since I've always done my CSS by hand I've never

used an automated tool, so I don't know a lot about the latter.

I have heard some good things about mincss, if you really want this

I recommend looking around for some tutorials and working yourself through

the docs.

I read about mincss and I really want to use it, but I don't know how. Their are no tutorials or any helpful links I could find. How do I install it and use it?

  • CPU:  Intel 3770k @ 4.4 GHz
  • Motherboard:  MSI Z77A-G45 
  • RAM:  16GB Corsair Vengeance 2133Mhz
  • Graphics:  EVGA GTX 970
  • PSU: Corsair AX850
  • Cooling:  Corsair H100i
  • Case: Fractal Design Define R5
  • Keyboard: Corsair STRAFE Cherry MX Red
  • Mouse: Razer DeathAdder
  • Headphones: Corsair Vengeance 1400
  • Monitor: BenQ XL2420TE 24" 1ms 144Hz

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-867674
Share on other sites

Link to post
Share on other sites

So you're afraid of having the same rule in two different files, so an inline entry plus externally linked entry? Just go through your inline stuff and if it exists externally, delete it from the .html file.

No. What I want to do is remove unused rules from my CSS file. You can take a look at my CSS file minified or non-minified at these links.

I've tested how many unused rules my CSS file has with Dust-Me Selectors a Firefox add-on and it said that out of all my rules, 1,993 of them are unused.

  • CPU:  Intel 3770k @ 4.4 GHz
  • Motherboard:  MSI Z77A-G45 
  • RAM:  16GB Corsair Vengeance 2133Mhz
  • Graphics:  EVGA GTX 970
  • PSU: Corsair AX850
  • Cooling:  Corsair H100i
  • Case: Fractal Design Define R5
  • Keyboard: Corsair STRAFE Cherry MX Red
  • Mouse: Razer DeathAdder
  • Headphones: Corsair Vengeance 1400
  • Monitor: BenQ XL2420TE 24" 1ms 144Hz

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-868914
Share on other sites

Link to post
Share on other sites

I read about mincss and I really want to use it, but I don't know how. Their are no tutorials or any helpful links I could find. How do I install it and use it?

What's your operating system and knowledge on Python? I have managed to get it

to run (I think ;)).

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-869574
Share on other sites

Link to post
Share on other sites

What's your operating system and knowledge on Python? I have managed to get it

to run (I think ;)).

I am currently running Windows 8, I have access to a Mac if needed and I could install Ubuntu on a partition if needed at all.

I currently have Python 2.7 installed on my Windows.

I have ZERO knowledge with Python.

  • CPU:  Intel 3770k @ 4.4 GHz
  • Motherboard:  MSI Z77A-G45 
  • RAM:  16GB Corsair Vengeance 2133Mhz
  • Graphics:  EVGA GTX 970
  • PSU: Corsair AX850
  • Cooling:  Corsair H100i
  • Case: Fractal Design Define R5
  • Keyboard: Corsair STRAFE Cherry MX Red
  • Mouse: Razer DeathAdder
  • Headphones: Corsair Vengeance 1400
  • Monitor: BenQ XL2420TE 24" 1ms 144Hz

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-871952
Share on other sites

Link to post
Share on other sites

Theres a Firefox add on for this, Dust-me selectors I think it's called. However a word of warning, if your site is dynamic or has multiple pages it is possible that these tools will get rid of selectors that actually are being used. Another example would be a heavily JavaScript powered website doing all sorts with selectors to trigger effects/animations/states may also fall through these tools

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-871973
Share on other sites

Link to post
Share on other sites

I am currently running Windows 8, I have access to a Mac if needed and I could install Ubuntu on a partition if needed at all.

I currently have Python 2.7 installed on my Windows.

I have ZERO knowledge with Python.

OK, that should work, before this I also had never actually worked

with Python. I'll put the info together tomorrow. It's Python 2

powered and needs two extensions/modules or whatever they are called

in Python (cssselect and lxml), see if you can install them already.

If you can get them to work on Win I don't think you'll need to switch

your OS, the Python console should work the same I hope (I've only

worked with it on Linux though).

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-872000
Share on other sites

Link to post
Share on other sites

Theres a Firefox add on for this, Dust-me selectors I think it's called. However a word of warning, if your site is dynamic or has multiple pages it is possible that these tools will get rid of selectors that actually are being used. Another example would be a heavily JavaScript powered website doing all sorts with selectors to trigger effects/animations/states may also fall through these tools

 

 

No. What I want to do is remove unused rules from my CSS file. You can take a look at my CSS file minified or non-minified at these links.

I've tested how many unused rules my CSS file has with Dust-Me Selectors a Firefox add-on and it said that out of all my rules, 1,993 of them are unused.

I've already used Dust-Me Selectors. The button it has to make a CSS file without the unused rules didn't work.

  • CPU:  Intel 3770k @ 4.4 GHz
  • Motherboard:  MSI Z77A-G45 
  • RAM:  16GB Corsair Vengeance 2133Mhz
  • Graphics:  EVGA GTX 970
  • PSU: Corsair AX850
  • Cooling:  Corsair H100i
  • Case: Fractal Design Define R5
  • Keyboard: Corsair STRAFE Cherry MX Red
  • Mouse: Razer DeathAdder
  • Headphones: Corsair Vengeance 1400
  • Monitor: BenQ XL2420TE 24" 1ms 144Hz

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-872126
Share on other sites

Link to post
Share on other sites

OK, that should work, before this I also had never actually worked

with Python. I'll put the info together tomorrow. It's Python 2

powered and needs two extensions/modules or whatever they are called

in Python (cssselect and lxml), see if you can install them already.

If you can get them to work on Win I don't think you'll need to switch

your OS, the Python console should work the same I hope (I've only

worked with it on Linux though).

I was able to install cssselect, lxml, and setuptools from these links, but I'm not sure if they were the correct one's I was supposed to install.

  • CPU:  Intel 3770k @ 4.4 GHz
  • Motherboard:  MSI Z77A-G45 
  • RAM:  16GB Corsair Vengeance 2133Mhz
  • Graphics:  EVGA GTX 970
  • PSU: Corsair AX850
  • Cooling:  Corsair H100i
  • Case: Fractal Design Define R5
  • Keyboard: Corsair STRAFE Cherry MX Red
  • Mouse: Razer DeathAdder
  • Headphones: Corsair Vengeance 1400
  • Monitor: BenQ XL2420TE 24" 1ms 144Hz

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-872267
Share on other sites

Link to post
Share on other sites

I was able to install cssselect, lxml, and setuptools from these links, but I'm not sure if they were the correct one's I was supposed to install.

Yeah I think those are the right ones.

I have made a small tutorial and put it into a separate thread so that it's easier to expand

and edit later on should that become necessary. Let me know if it does or does not work for you.

Cheers,

-aw

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-874137
Share on other sites

Link to post
Share on other sites

Yeah I think those are the right ones.

I have made a small tutorial and put it into a separate thread so that it's easier to expand

and edit later on should that become necessary. Let me know if it does or does not work for you.

Cheers,

-aw

Yes! Thank you very much! Worked like a charm!

  • CPU:  Intel 3770k @ 4.4 GHz
  • Motherboard:  MSI Z77A-G45 
  • RAM:  16GB Corsair Vengeance 2133Mhz
  • Graphics:  EVGA GTX 970
  • PSU: Corsair AX850
  • Cooling:  Corsair H100i
  • Case: Fractal Design Define R5
  • Keyboard: Corsair STRAFE Cherry MX Red
  • Mouse: Razer DeathAdder
  • Headphones: Corsair Vengeance 1400
  • Monitor: BenQ XL2420TE 24" 1ms 144Hz

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-876233
Share on other sites

Link to post
Share on other sites

Yes! Thank you very much! Worked like a charm!

Cool, happy to help! :)

BUILD LOGS: HELIOS - Latest Update: 2015-SEP-06 ::: ZEUS - BOTW 2013-JUN-28 ::: APOLLO - Complete: 2014-MAY-10
OTHER STUFF: Cable Lacing Tutorial ::: What Is ZFS? ::: mincss Primer ::: LSI RAID Card Flashing Tutorial
FORUM INFO: Community Standards ::: The Moderating Team ::: 10TB+ Storage Showoff Topic

Link to comment
https://linustechtips.com/topic/63412-remove-unused-css/#findComment-877652
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×