Remove Unused CSS Code

Discussion in 'CSS' started by ceint_com, Jan 25, 2011.

  1. #1
    Is there some automated way or script I can use to find and preferably delete all the unused CSS on my site?
     
    ceint_com, Jan 25, 2011 IP
  2. grahamatdp

    grahamatdp Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you use Firefox, you can install a plugin called Dust-Me Selectors and use that to locate unused CSS.
    Then, simply strip the stuff you don't need out of your stylesheet(s).
     
    grahamatdp, Jan 25, 2011 IP
  3. ceint_com

    ceint_com Active Member

    Messages:
    312
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    78
    #3
    Thank you! I was hoping for a more "automated" way. Guess I'm lazy :)
     
    ceint_com, Jan 25, 2011 IP
  4. CSM

    CSM Active Member

    Messages:
    1,047
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    55
    #4
    There is not much to "automate" such a process.

    The problem is that e.g. Google Page Speed addon can tell you what CSS code is "unused", but the addon is not correct.
    What the addon tells you is that the CSS code that is "unused" is only not necessary to render the site after it got loaded.

    That's why I delete unused CSS by hand, I know what I have added there and I know which code can be deleted.
     
    CSM, Jan 25, 2011 IP
  5. steelfrog

    steelfrog Peon

    Messages:
    537
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Automation is dangerous. If it scans a page and returns a handful of classes that aren't used on that specific page, it doesn't necessarily mean it's not in use elsewhere.
     
    steelfrog, Jan 25, 2011 IP
  6. radiant_luv

    radiant_luv Peon

    Messages:
    1,327
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Well, it already said above, screen your styles wihtout automation.
     
    radiant_luv, Jan 25, 2011 IP
  7. AtSeaDesign

    AtSeaDesign Active Member

    Messages:
    172
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    93
    #7
    Google Page Speed tells you the unused CSS ON THE PAGE YOUR VIEWING. Not the entire site. So be careful that your 'unused' styles are not needed on sub pages.
     
    AtSeaDesign, Jan 27, 2011 IP
  8. marc marc

    marc marc Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You can try http://Unused-CSS.com. I think it does what you want.
     
    marc marc, Jan 29, 2011 IP