Rendering styles

The question is - what will a browser do, given a page with several stylesheets, each of them probably overwriting definitions from the previous ones? Will the browser render the page using the first received css file, while downloading the other ones and after that partially re-rendering where required? The answer is: no, the browser will wait until all CSS files are downloaded, (then probably merge all definitions, just a wild guess) and will render once.

Test

I did this test - one page with two stylesheets that contain pretty much the same selectors for different table styles (thanks to this gallery). Each of the CSS files is actually a PHP script and has a call to sleep(), one sleeps for 5 seconds, the other one for 10.

Result

The browser sits there and waits for the both styles, rendering nothing (except for the page title, but that's not really rendering, is it?). So nothing happens for 10 seconds, then the second style is used for the final rendering. This happens in both FF and IE.

Misc

I also tried sleeping in the actual page, and flushing the output after each row. In my home environment FF renders each row as it's received, but in my hosted environment, it waits for the whole table. IE alsways waits for the complete table.

If I put the page to too much sleep so that the php script dies before the second stylesheet is dowloaded, the browser uses whatever is at hand (css1) to render the page.

Demo/download

This entry was posted on Wednesday, October 4th, 2006 and is filed under browsers, CSS, firefox. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

9 Responses to “Rendering styles”

  1. phpied.com » Blog Archive » Delay loading your print CSS Says:

    [...] The thing is, when it comes to performance, the browser won’t render any part of the page, until all stylesheets are downloaded (fiddled with here). That includes, unfortunately, stylesheets not designed for the currently rendered media. In other words, the browser won’t display your page, until the print stylesheet is also downloaded, although it’s not used at all for displaying the page. That sucks and should really be addressed in future browser versions. [...]

  2. Mytskine Says:

    This article always speaks about “the browser” but in the last paragraphs we learn that it’s just FF and IE (which versions?). As far as I know, there are no recommandation of W3C on the subject, so each browser is free to act as it wants to. For instance, have a look at Opera8/9, it behaves differently. And Safari or konqueror or new versions of FF might be smart, too.

  3. Stoyan Says:

    Thanks Mytskine for the comment. You’re right – Opera does render the page, then re-renders when the first css arrives, the does it again when the second css arrives.

    I tested again with the latest IE, FF and Safari (on Windows) – they all wait for all css files, before rendering. It makes sense in a way, because re-rendering the page can be expensive and doing it several times in one request is probably something browsers want to avoid.

  4. phpied.com » Blog Archive » Weird attempt for flicker-free rendering solution Says:

    [...] Another idea – as shown in a previous post, the browsers (except Opera) won’t show anything until the last bit of CSS is downloaded. So if you put you big-ass CSS file at the bottom of the page (which is exactly the opposite of what you should be doing when aiming at performance) you might also achieve the desired flicker-free rendering. Post this entry to: » del.icio.us  » Digg  » Furl  » Newsvine  » reddit  » Y! [...]

  5. Image Optimization, Part 5: AlphaImageLoader » Yahoo! User Interface Blog Says:

    [...] way — since IE will not render anything until the very last bit of CSS comes down the wire (more info), and your because CSS has a dependency on a filtered image, the rendering is blocked until the [...]

  6. Nemo Says:

    Stoyan,

    does this means that browsers won’t download background images referenced in an external style sheet before a flush()?

    Said otherwise, does the technik you explain here:

    http://www.phpied.com/progressive-rendering-via-multiple-flushes/

    applied to style sheets speeds up the download of background images?

  7. architectural rendering Says:

    architectural rendering…

    [...]Rendering styles / Stoyan’s phpied.com[...]…

  8. CSS and the critical path / Stoyan's phpied.com Says:

    [...] block rendering until all CSS arrives. With the worst possible experience: white [...]

  9. Kemberly Huneycutt Says:

    Sleeping for too long can damage your circadian rhythm. The circadian rhythm is your 24 hour ‘clock’ controlled by a central part of the brain. This clock tells us when we are sleepy by altering the body temperature by a few degrees. When the body temperature is lowered, we feel sleepy. Conversely when it is raised, we feel awake and alert.;

    Check out the most recently released blog post on our own website
    <.http://www.foodsupplementcenter.com/magnesium-for-migraines/

Leave a Reply