Single CSS File or Multiple?

Discussion in 'CSS' started by sidious1990, Jun 30, 2009.

  1. #1
    My site has several pages that are very different from each other.

    Would it be better to use one CSS file or one for each page? (I have around 5 pages that are different from each other - the rest are the same.)
     
    sidious1990, Jun 30, 2009 IP
  2. qazu

    qazu Well-Known Member

    Messages:
    1,834
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #2
    You mean they have different layout? If they do I'd use separate css for each layout.
     
    qazu, Jun 30, 2009 IP
  3. sidious1990

    sidious1990 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well some elements are the same, such as the logo, menu etc but the main body is layed out differently.

    Maybe I should just section out my CSS file for the different pages?
     
    sidious1990, Jun 30, 2009 IP
  4. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If the layout and grid are large differences, you had better to use multiply css files,
    Otherwise use one css file.
     
    justinlorder, Jul 1, 2009 IP
  5. qazu

    qazu Well-Known Member

    Messages:
    1,834
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #5
    In that case I'd have one for the elements that are the same, and then different ones for the layout changes if they are substantial changes. If they're only a few then you might as well have them in one css file.
     
    qazu, Jul 1, 2009 IP
  6. Kazumael

    Kazumael Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yep, I agree on that one. Depending on the size of these CSS files, you might want to create one bigger file and clean your CSS somewhat. This reduces loading times since your reduce the amount of HTTP GET request.

    After this first load, all files will be present in the browsers cache, and don't need to be downloaded again :)
     
    Kazumael, Jul 2, 2009 IP
  7. WebDizajnSajter

    WebDizajnSajter Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    One css file is enough, because big ones with 1,000 lines or more, are about 20 Kb. To understand better what it is going on in the css file, put comments above sections like this /* add descriptions*/. It is much simpler to connect to one external css file than multiple ones.
     
    WebDizajnSajter, Jul 2, 2009 IP
  8. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Agreed. I want to have all my styles in just one document, which I can ctrl+f in to find everything. Multiple files is a pain.

    There are exceptions though. My husband's company has a base CSS file, and that single website serves many newspapers, who want their own header styles. So it made more sense in that case to have a
    basis.css
    and then tacked onto the bottom (a second css link in the <head>) the header-specific styles for that newspaper:
    dailytimes.css

    It was easier for the server, since most people visiting one newspaper don't go to visit other ones, so it's still just 2 css files and not several.

    None of my sites, even those with styles for IE6 that are completely different from other browsers, have more than a single stylesheet.
     
    Stomme poes, Jul 3, 2009 IP
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #9
    Or use classnames and ID's that actually identify what the elements ARE, not how they appear (see why CSS frameworks are made of /FAIL/)

    It really is a loaded question - As a rule I like to say that I prefer only one CSS file per media type, and I try to avoid sharing a CSS file across media types, but truly if just one page that not every visitor is going to go to has unique elements on it, I say go ahead and make one more file... But that's it.

    So one file preferred, but certainly no more than two files per media type.

    You do include a media attribute, right?
     
    deathshadow, Jul 3, 2009 IP