作者: xcntime 发表于 2010-08-11 10:47 原文链接 阅读: 0 评论: 0
Some pages that use the CSS @import rule experience a curious display quirk in the Windows version of MS Internet Explorer: a momentary flash of unstyled page content. The unimaginative creature that I am, I call this phenomenon Flash of Unstyled Content or FOUC for short.
Because this quirk seems to affect only MS Internet Explorer, we're tempted to conclude that IE is just plain wrong. I am not going to jump to that conclusion. It is unclear to me whether or not a FOUC afflicted user agent is in disagreement with any W3C recommendation. Though I can't speak for the W3C, I can say that I would prefer that Internet Explorer ditch the flash of unstyled content.
First, you will need to be using IE for Windows (version 5 or above). Then, you'll need to find a page that exhibits the FOUC phenomenon. You won't need to search long - this very page¹ is a great example.
Now, this is very important. If the imported stylesheet is in IE's cache (also called Temporary Internet Files), the flash of unstyled content will not rear its ugly head. For testing purposes, delete IE's Temporary Internet Files before viewing the FOUC-inducing page. If you're not sure how to do this, please refer to Microsoft's brief online instructions. Below is my suggested method to test for a FOUC.
Please note that some factors, like a slow PC or proximity to network equipment with caching capabilities, may reduce the chance that you'll witness the flash of unstyled content display quirk. For example, I have a 100MHz Pentium PC running IE5/Win that will not exhibit this phenomenon for even the worst FOUC-afflicted pages.
When I first converted bluerobot.com to a CSS-based layout (18 FEB 2001), the design suffered from the FOUC phenomenon. It was immediately clear that this odd display quirk was somehow connected to the use of the CSS2 @import rule. Because the @import rule is widely used to hide complex CSS rules from CSS-impaired browsers (e.g. Netscape Navigator 4.x), the FOUC phenomenon has the potential to be more than just a small annoyance.
That said, I must admit that I've only recently given the FOUC issue more than a passing thought. The split-second rendering of raw content seemed somehow fitting on the BlueRobot home page. However, I've received too many emails regarding this issue to pretend that it's not a concern.
So, why do some pages (e.g. this page¹) exhibit the FOUC, while others (e.g. A List Apart) do not? Well, the ALA home page sure has more stuff inside its HEAD
element than does this page. Of particular interest, the HEAD
element on the ALA home page contains a couple of SCRIPT
elements and a handful of LINK
elements, while this page¹ contains no such elements. There's a solution in there somewhere.
Just one LINK
element or SCRIPT
element inside a document's HEAD
element will prevent a flash of unstyled content.
HEAD
elementFor the purposes of comparison, below is the basic HEAD
element that is susceptible to the FOUC phenomenon.
Test the basic HEAD element for the FOUC phenomenon.
The addition of a LINK
element to the basic HEAD
element is probably the most natural solution to the FOUC problem. This is because almost every page can benefit from the addition of either an alternate stylesheet or a media-dependent stylesheet. I recommend this solution, because it both prevents the FOUC display quirk and improves the page in some other way: either usability, accessibility, or some other fancy buzzword. Of course, this solution works even if the added LINK
element refers to an empty stylesheet. But what a waste that would be.
Test the LINK element solution for the FOUC phenomenon.
The addition of a SCRIPT
element to the basic HEAD
element is an effective solution to the FOUC problem. However, it may seem somewhat unnatural to add a SCRIPT
element to some pages. For example, I believe there is no script that would improve this page. I could add an empty SCRIPT
element to the HEAD
of this page, but that feels an awful lot like a hack. In cases like this, opt for the LINK
element solution.
I should mention here that the SCRIPT
element does not need to be inside the HEAD
element to thwart the FOUC phenomenon. It does need to appear in the markup before all content contained by the BODY
element. Therefore, placing a SCRIPT
element inside the BODY
element, but before all visual content, is also an effective way to prevent a FOUC.
Test the SCRIPT element solution for the FOUC phenomenon.
If you know of any resources on the FOUC phenomenon, or have any related information for me, please let me know. There must be more information out there. I'd like to continue to improve our understanding of this pesky display quirk. And for heaven's sake, please let me know if you encounter any problems or errant information on this page. I appreciate any and all help.
I'd like to give a special thanks to Shawn Wall for sharing ideas, testing pages, and generally motivating me to get off my butt and write this document.
¹When no solution is in effect, this page exhibits the flash of unstyled content display quirk. However, some links on this page dynamically modify the page markup to demonstrate solutions to the FOUC problem. No FOUC solutions are currently in effect.
评论: 0 查看评论 发表评论
程序员找工作,就在博客园
最新新闻:
· 深藏在 Gmail 中的 Google Buzz / Google Laitutde /Gtalk 组(2010-08-16 22:11)
· 10 款网页设计师必知的免费 Android 应用(2010-08-16 21:30)
· 中易起诉微软案本月终审 专家称微软严重侵权(2010-08-16 21:28)
· 创业者必须自问的三个问题(2010-08-16 21:17)
· 苹果夺面双雄:1979年图形输入板与iPad比较(2010-08-16 21:10)
编辑推荐:Twitter如何在数千台服务器上快速部署代码?
网站导航:博客园首页 个人主页 新闻 闪存 小组 博问 社区 知识库