tags:

views:

192

answers:

6

I have an ecommerce site that has about 8 CSS files linked from the header - resulting in 8 separate http requests to the server. I consolidated all the CSS files into 1 big one, resulting in a 67kb (!) file - to cut down the http requests to 1 for our css files.

I'm finding this size a CSS file a little unmanageable in light of the fact I'm performing updates on the site constantly. My concern is my users may catch me in the middle of updating and see a NON-styled page when moving from page to page - b/c 67kb still takes a good 2-3 seconds before it is successfully placed on the remote server via FTP.

My question is: does the use of @import within this large CSS file to break up the files into smaller more manageable sizes (within that CSS file) take us back to the original 8 http-requests when the pages is loaded? Or are @imports in CSS handle differently somehow?

+8  A: 

Yeah you will go back to a request per each stylesheet while using @import.

Your best bet is to minify and consolidate the css into a single file for deployment. But you can still develop with seperate files.

Corey Downie
thank you - I feared as much. :(i did try minifying - but it broke the site for whatever reason. i'll have to give that another try and perhaps look at WHY it's coming apart. Many thanks.
Mo Boho
consolidating into a single css file is likely going to give you a larger benefit (1 http request) than shaving a few bytes off with minifying, I would concentrate on the single file for deployment first
Corey Downie
When you say "concentrate" - do you mean cut down on the "bloat" in the CSS? I have a fairly good understanding of CSS and shortcuts to cut down on excess code - so I've "trimmed" a lot of fat already. Is there something else you might mean?
Mo Boho
By 'consolidate' I just mean to turn your 8 css files into 1 big one when you deploy. I'm not sure what platform you are using, but using .net I have done this in the past using an httphandler.
Corey Downie
+2  A: 

The browser has to get the data somehow, so how could it not use another http request? ;-)

It's also possible though, that you'll benefit from browser caching if you're only changing one file and the other seven are unchanged.

You might try sniffing a connection between a client and the server and see what it requests.

Mike Kale
thank you, Mike.
Mo Boho
+1  A: 

Yes, a separate request is issued for each @import statement.

You can check this with a quick test; write a fragment of HTML, including a CSS file which imports a second CSS file. Viewing the results in something like Firebug's network panel shows two separate requests for each CSS file. That's the test I used to confirm this answer.

Rob
+1  A: 

CSS imports are not handled any differently than any other "include" on a page, such as a reference to an external JavaScript script. However, browser caching should make this a non-issue except for the first access to your site.

Eddie
yeah - i think I'm going to go back to breaking them down into more manageable files. :) it's true after the first page load, it shouldn't be a concern.
Mo Boho
A: 

If you have a 67 Kb CSS file there is something strange. Remember that the C in CSS is for CASCADING, and this means that you don't have to define in each class all the properties of each one of the tags involved in the class.

For example if you define a <DIV id="maincontainer"> as a container you can define a class to it

#maincontainer {font-face:Arial,helvetica,sans;}

It means that if you create a sub-class of it for the tag <P> like

#maincontainer P {color:darkgray;}

All the <P> tags inside the DIV maincontainer will use font arial, helvetica, sanz.

Also try to create CSS files in order to how them are used in the pages. A unique CSS file for all the site makes to load a lot of classes that are not going to be used in some pages. Divide and conquer.

backslash17
i had thought of that - the only problem is the site is template driven and not so easy to customize on a section-by-section basis.But as Eddie and others have pointed out - after the first loading, the browser cache should take care of the rest.
Mo Boho
You can also create dynamic CSS fiels. It means CSS files created at server side customized for each part of your app.
backslash17
A: 

add then as "link href="