Tools to optimize (remove redundancy and merge) CSS?

46,260

I don't particularly understand what you mean by "clean unused CSS", but in any case, I'll throw two tools at you, and maybe one will work (the good ol' shotgun approach).

CSS Lint seems to point out "duplicate properties". There are a range of articles covering some of what it does. But a test with the two definitions you had,

a { color: #fff; }
a { color: #000; }

it didn't do much of anything. While ...

Code Beautifier did combine the two selectors, opting for the latter of the two (i.e. the style that's actually applied). Resulting in:

a {
  color:#000;
}
Share:
46,260

Related videos on Youtube

Lucian Povatanu
Author by

Lucian Povatanu

Updated on July 09, 2022

Comments

  • Lucian Povatanu
    Lucian Povatanu almost 2 years

    I'm searching for a good CSS compress, merge and optimization tool. I have found tools that clean the CSS but they don't optimize the overwrites.

    Here is a basic example:

    a{color:#000}

    and on another line the a color is overwritten with this:

    a{color:#fff}

    Does anyone know of a tool that can clean the unused CSS, that was overwritten and keep just the applied style?

    • Admin
      Admin almost 12 years
      I edited the title. Just "compression" and "minifying" are orthogonal to actual smart-optimization of CSS. This is a fairly interesting question, although I would normally vote-to-close such "find me a tool" questions ..
    • Whymarrh
      Whymarrh almost 12 years
      CodeKit is a OS X application for things like that. Not sure if it does the specifics though.
    • Lucian Povatanu
      Lucian Povatanu almost 12 years
      Tks pst .Tks Whymarrh,but I can't test CodeKit app, I'm a Win/Linux user :)
    • Whymarrh
      Whymarrh almost 12 years
      @LucianPovatanu maybe something from this question will help.
    • Lucian Povatanu
      Lucian Povatanu almost 12 years
      @Whymarrh tks for that link, but what I was asking is a tool that can clean used or unused css overwrites, so an "unused css cleaner" isnt the answer.
    • The One and Only ChemistryBlob
      The One and Only ChemistryBlob almost 7 years
      I just responded to this post - stackoverflow.com/questions/25320591/…. Try CSSBurner - it seems to be able to optimize in the way you are looking for. CSSLint has nice UI but doesn't seem to do what you are asking for
    • AEQ
      AEQ over 6 years
      Just updated our Node JS tool: rbtech.github.io/css-purge
  • Lucian Povatanu
    Lucian Povatanu almost 12 years
    "Merge duplicate properties" is the tool that I was searching, tks @Whymarrh
  • Christopher
    Christopher about 7 years
    I found this site helpful while searching for this sort of thing too ... just FYI: refresh-sf.com
  • AEQ
    AEQ over 6 years
    Just updated our Node JS tool: rbtech.github.io/css-purge