Use multiple external stylesheets or as few as possible? pros and cons

I've been searching for CSS best practices, pondering what best practices my code supports, and I'm reading something that is really against pretty much everything I've learned, but it comes from Google. I always prefer to use multiple stylesheets. I find it better to maintain the code and also my code does not load multiple CSS classes that will not be used.

Google developer directs us to the exact opposite:

Combining external stylesheets into as few files as possible reduces RTT response times and latency when loading other resources.

Here are some rules of thumb for bundling your CSS files into production, which they also recommend:

  • Divide the CSS into 2 files each: one CSS file containing the minimum code needed to render the page at startup; and one CSS file containing code that is not needed until the page has finished loading.
  • Serve the CSS of a rarely visited component in its own file. Serve the file only when the user requests this component.
  • For CSS that shouldn't be cached, consider nesting them.
  • Don't use CSS @import from CSS file.

Indeed ... Google recommends inline css when css won't be cached? or use less css files as possible? (of course we don't have to use css for every thing, but we always read experimenter web designers recommending using multiple stylesheets, so I'm really confused (if it didn't come from google I would ignore it, but how is it I thought about asking the opinion of stackoverflow users because I think it might be helpful for others as well).

PS: Here you can find the address of the information I posted .

+3


source to share


2 answers


Page requests usually take longer than loading a few extra bytes. This is why Google suggests what they do. This is really imo best practice and this is also what I am doing.



Just to keep your code organized, you should consider working with a css preprocessor like less (lesscss.org). This way you can keep your code in separate files for ease of development. Then you use a bunch of @import statements in your master less and compile them to css. This is the only css file that needs to be loaded on your page. Make sure to load @import files without files, not .css files, as the latter will generate an additional page request.

+2


source


Well, when you write code, you can keep it all in separate stylesheets, and then you can dump it all at the end.

This is for mobile users, so your page will make fewer server requests and go faster. CSS sprites are the same idea and there are graphic compressors. And a lot of information available on responsive design.

http://www.speedawarenessmonth.com/15-things-for-making-your-site-faster-for-mobile-users/



You may be looking for tools like Less or Sass to make it easier: Read: http://coding.smashingmagazine.com/2010/12/06/using-the-less-css-preprocessor-for-smarter-style- sheets /

Download: http://crunchapp.net/

+1


source







All Articles