What is it? Well, there are two different ways of explaining it:
- To the viewer, it's that annoying white flash that you see every time you view a different page on a website when the website has a background image or background color that isn't white.
- To the web coder, it's that short moment of time during which the page is unstyled (defaulting to a blank white page) that annoys the viewers.
Let's fix it! :)
Don't waste your time doing research that I've already done. The problem is abbreviated as FOUC (Flash of Unstyled Content), and these are a bunch of links that I discovered during my research that suggest potential solutions (don't feel obligated to check them out yet - I will provide my favorite solution below):
White flash in IE HTML forum at WebmasterWorld:
Stop IE Page Load Flicker | CSS-Tricks:
IE image flicker on page load problem CSS forum at WebmasterWorld:
IE7 and page load flickering | CSS Creator:
Smoothing Out Page Transitions:
cookies - Jquery Style switcher - How to remove style flickering while a .css loads? - Stack Overflow:
Page flickers badly when loading in IE HTML forum at WebmasterWorld:
Avoiding the FOUC v3.0 « Paul Irish:
The FOUC is most effectively fixed by recognizing that you as the web coder need to minimize (or, if possible, eliminate) the duration of there being any unstyled content displayed. Let's take a look at two example pages that I've set up (they both have a link to each other so I've only linked to the first here):
Yuck! If you click the links a couple of times and the FOUC stops appearing, press Ctrl + F5 for a full refresh and it should be visible again (at least for that refresh).
Here's the code for the first page (it's almost identical to the second page, other than the link):
<html> <head> </head> <body style="margin:0; padding:0;"> <div style="width:100%; height:100%; margin:0; padding:0; background-image: url('bg.png'); background-size: 100%;"> <a href="secondpage.html">Click here to go to the second page.</a> </div> </body> </html>
The setup is pretty simple: there's a div that takes up the entire page and displays a background image for the website.
Here's the updated code:
Simple enough! Hopefully this is an approach that you are willing and able to take - the only three downsides to this approach that I'm aware of are:
- It doesn't work perfectly in Internet Explorer. That's why I also set the background color to black in the JS code, because black is a good intermediate color for the minimized FOUC that still displays for a little bit.
I'm fairly certain that this fix only works by including an external CSS file using "link" - or so I've read.
- You may want your background image/color to be in e.g. a "div" element rather than in the body. If this is the case, try reading and applying this.
You should know that I prefer easy, practical solutions that fix problems for most modern viewers and that this solution isn't 100% perfect/applicable to all website viewers, but it's good enough if you ask me. Lastly, do note that I also set a background color in my solution example in case you are using just a background color and not an image.
So with all of that said, I hope I have at the very least helped you to understand and fix your FOUC problem(s)!