March 18, 2012

Multiple css files or one big css file?

Question by Alex90

Which one is better and faster? why?

using only one file for styling:

css/style.css

or

using several files for styling:

css/header.css
css/contact.css
css/footer.css
css/tooltip.css

The reason Im asking it is that im developing a site for users who have very low internet speed. country uganda. So I want to make it as fast as possible.

Answer by hustlerinc

Using a single file is faster because it requires less HTTP requests (assuming the amount of styles loaded is still the same).

So it’s better to keep it in just one file.
Separating CSS should only be done if you want to keep for example IE specific classes separate.

Answer by Starx

As per Yahoo’s Performance Rules [source], It is VERY IMPORTANT to minimize HTTP requests

From the source

Combined files are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining
all CSS into a single stylesheet. Combining files is more challenging
when the scripts and stylesheets vary from page to page, but making
this part of your release process improves response times.

It is quite uneasy to develop using combined files, so stick to developing with multiple files but you should combine the files once you are deploying the system on the web.

I really recommend using boilerplate’s ant build script. You can find it here.

It Combines and minifies CSS

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!