treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Separate CSS files VS One CSS file (@Media)

  • hi all,

    Can I hear your thoughts on which one of these gives best performance in the would of responsive web design.

    Example of separate CSS files -

    <link rel="stylesheet" media="screen" href="main.css">
    <link rel="stylesheet" media="only screen and (min-width: 480px)" href="480.css">
    

    Example of one CSS file -

    @media only screen and (min-width: 480px) {
      /* Style */
    }
    @media only screen and (min-width: 768px) {
     /* Style */
    }
    
  • Afaik any browser will load both stylesheets, no matter if the media query matches or not. so from a pure performance view the latter alternative should be just a tiny bit better. But from a maintainability point of view i would tend to use the first version anyway :)

  • I think that the first way is better. While browsers will load both, some newer browsers (latest WebKit) will delay the loading of a stylesheet that doesn't currently apply until after the page has been shown and everything else has been loaded.