CSS program question?

Discussion in 'Web Design and Development' started by DesignIt, Dec 19, 2005.

  1. DesignIt macrumors member

    Aug 2, 2005
    Does anybody know of a program that will go thru a style sheet and remove any unused styles?

    That would be a helpful program. :D
  2. mnkeybsness macrumors 68030


    Jun 25, 2001
    Moneyapolis, Minnesota
    How would it know what is used and what is not?

    A good stylesheet should only be written to include styles that are used on your pages and your layout should reuse styles as needed so that you don't end up with 4 classes that do the same thing.

    It's all a matter of planning.
  3. munkle macrumors 68030


    Aug 7, 2004
    On a jet plane
    Of course ideally that would be the case but a lot of sites (especially blogs) aren't built from scratch by people knowledgeable in CSS but hacked from a pre-supplied template...I may or may not be speaking from experience :eek: :p
  4. floyde macrumors 6502a


    Apr 7, 2005
    Monterrey, México
    It could read the whole HTML looking for the "class" or "id" (on divs) attributes, and then it could match it to the CSS stylesheet. I haven't heard of such a program though.
  5. Josh macrumors 68000


    Mar 4, 2004
    State College, PA
    You could set up a simple shell script that would search for (using grep) all instances of <div id="*"> and <div class="*"> within the HTML file, then have it replace <div id="*"> with #*, and <div class="*"> with .*, and save that as a new document.

    Then you'd pretty much just have to compare the two on your own. The script could search for common instances, but it would have no idea of knowing what is a propery and what is a name, so you'd be left with only the names of the ids and classes. I guess that could then be used to help you know which ones are safe to delete, though.

Share This Page