CSS program question?

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

  1. macrumors member

    Joined:
    Aug 2, 2005
    #1
    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. macrumors 68030

    mnkeybsness

    Joined:
    Jun 25, 2001
    Location:
    Moneyapolis, Minnesota
    #2
    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. macrumors 68030

    munkle

    Joined:
    Aug 7, 2004
    Location:
    On a jet plane
    #3
    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. macrumors 6502a

    floyde

    Joined:
    Apr 7, 2005
    Location:
    Monterrey, México
    #4
    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. macrumors 68000

    Josh

    Joined:
    Mar 4, 2004
    Location:
    State College, PA
    #5
    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