为什么网页不立即显示它们的文本?

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。...

为什么网页不立即显示它们的文本? If you’re prone to watching the browser pane with an eagle eye, you may have noticed that pages frequently load their images and layout before loading their text–the exact opposite loading pattern we experienced during the 1990s. What’s going on?

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

问题

超级用户读者Laurent非常好奇为什么页面加载的元素与以前完全不同。他写道:

I’ve noticed that recently many websites are slow to display their text. Usually, the background, images and so on are going to be loaded, but no text. After some time the text starts appearing here and there (not always all of it at the same time).

It basically works the opposite as it used to, when the text was displayed first, then the images and the rest was loading afterwards. What new technology is creating this issue? Any idea?

Note that I’m on a slow connection, which probably accentuates the problem.

See [above] for an example – everything’s loaded but it takes a few more seconds before the text is finally displayed.

那是什么原因呢?劳伦特和我们中的许多人都记得,有一段时间,文本首先加载,而其他所有东西——加里什动画gif、平铺背景和90年代后期网络浏览的所有其他人工制品——都是后来才加载的。是什么原因造成了设计元素先设计后文本的现状?

答案

超级用户贡献者Daniel Andersson提供了一个非常详细的答案,可以从根本上解释为什么字体会加载最后一个谜:

One reason is that web designers nowadays like to use web fonts (usually in WOFF format), e.g. throughGoogle Web fonts.

Previously, the only fonts that were able to be displayed on a site was those that the user had locally installed. Since e.g. Mac and Windows users not necessarily had the same fonts, designers instinctively always defined rules as

font-family: Arial, Helvetica, sans-serif;

where, if the first font wasn’t found on the system, the browser would look for the second, and lastly a fallback “sans-serif” font.

Now, one can give a font URL as a CSS rule to get the browser to download a font, as such:

@import url(http://fonts.googleapis.com/css?family=Droid+Serif:400,700);

and then load the font for a specific element by e.g.:

font-family: 'Droid Serif',sans-serif;

This is very popular to be able to use custom fonts, but it also leads to the problem that no text is displayed until the resource has been loaded by the browser, which includes the download time, the font loading time and the render time. I expect that this is the artifact that you are experiencing.

As an example: one of my national newspapers, Dagens Nyheter, use web fonts for their headlines, but not their leads, so when that site is loaded I usually see the leads first, and half a second later all the blank spaces above are populated with headlines (this is true on Chrome and Opera, at least. Haven’t tried others).

(Also, designers sprinkle JavaScript absolutely everywhere these days, so maybe someone is trying to do something clever with the text, which is why it is delayed. That would be very site specific, though: the general tendency for text to be delayed in these times is the web fonts issue described above, I believe.)

Addition:

This answer became very upvoted, though I didn’t go into much detail, or perhaps because of this. There have been many comments in the question thread, so I’ll try to expand a bit […]

The phenomenon is apparently known as “flash of unstyled content” in general, and “flash of unstyled text” in particular. Searching for “FOUC” and “FOUT” gives more info.

I can recommend web designer Paul Irish’s post on FOUT in connection with web fonts.

What one can note is that different browsers handle this differently. I wrote above that I had tested Opera and Chrome, who both behaved similarly. All WebKit based ones (Chrome, Safari, etc.) choose to avoid FOUT by not rendering web font text with a fallback font during the web font loading period. Even if the web font is cached, there will be a render delay. There are a lot of comments in this question thread saying otherwise and that it is flat out wrong that cached fonts behave like this, but e.g. from the above link:

In what cases will you get a FOUT

  • Will: Downloading and displaying a remote ttf/otf/woff
  • Will: Displaying a cached ttf/otf/woff
  • Will: Downloading and displaying a data-uri ttf/otf/woff
  • Will: Displaying a cached data-uri ttf/otf/woff
  • Will not: Displaying a font that is already installed and named in your traditional font stack
  • Will not: Displaying a font that is installed and named using the local() location

Since Chrome waits until the FOUT risk is gone before rendering, this gives a delay. To which extent the effect is visible (especially when loading from cache) seems to be dependent on among other things the amount of text that needs to be rendered and perhaps other factors, but caching does not completely remove the effect.

Irish also has some updates concerning browser behavior as of 2011–04–14 at the bottom of the post:

  • Firefox (as of FFb11 and FF4 Final) no longer has a FOUT! Wooohoo!http://bugzil.la/499292 Basically the text is invisible for 3 seconds, and then it brings back the fallback font. The webfont will probably load within those three seconds though… hopefully..
  • IE9 supports WOFF and TTF and OTF (though it requires an embedding bitset thing– mostly moot if you use WOFF). HOWEVER!!! IE9 has a FOUT. :(
  • Webkit has a patch waiting to land to show fallback text after 0.5 seconds. So same behavior as FF but 0.5s instead of 3s.

If this was a question aimed for designers, one could go into ways to avoid these kinds of problems such as webfontloader, but that would be another question. The Paul Irish link goes into further detail on this matter.


有什么要补充解释的吗?在评论中发出声音。想从其他精通技术的堆栈交换用户那里阅读更多答案吗?请查看此处的完整讨论线程。

 

  • 发表于 2021-04-11 21:33
  • 阅读 ( 142 )
  • 分类:互联网

你可能感兴趣的文章

为什么要从onenote 2016切换到onenote for windows 10

... 为什么onenote for windows 10优于onenote 2016 ...

  • 发布于 2021-03-24 12:37
  • 阅读 ( 395 )

7个小贴士让iphone上的网页更具可读性

...媒体上的配色方案。 让你的iphone读给你听 既然你能听,为什么还要读书?苹果的**和平板电脑都有一个无障碍选项,可以读出当前的屏幕、网页或抄写的文字。虽然这首先是针对视力受损者的可访问性功能,但它在消费书面内...

  • 发布于 2021-04-02 00:18
  • 阅读 ( 204 )

如何在microsoft word中插入、删除和管理超链接

...rd文档中**、管理和删除不同类型的超链接。 **指向外部网页的超链接 您可以将word文档中的单词或短语链接到外部网页,它们的工作方式与您在web上找到的链接非常相似。首先,在web浏览器中加载要链接到的网页。您只需要复...

  • 发布于 2021-04-05 08:12
  • 阅读 ( 168 )

为什么我从chrome切换到firefox quantum

从FirefoxQuantum正式发布前开始,我已经连续使用了一个多星期了。多年来,我觉得每一个Firefox版本都比Chrome慢。但是火狐现在又是一个真正的、快速的、现代的选择。足够让我从Chrome切换回Firefox。 当然,很高兴Firefox处于劣势...

  • 发布于 2021-04-07 02:08
  • 阅读 ( 207 )

如何增加chromebook上的文本大小

...有的东西都太小了,你会想放大整个系统。这将包括所有网页和系统设置,但不幸的是不会影响文件管理器或墙纸选取器之类的事情。也就是说,它仍然有帮助,因为它覆盖了95%的时间,你可能会花时间。 首先,单击右下角的...

  • 发布于 2021-04-08 10:59
  • 阅读 ( 177 )

为什么网页不立即显示它们的文本?

...动的问答网站分组。 问题 超级用户读者Laurent非常好奇为什么页面加载的元素与以前完全不同。他写道: I’ve noticed that recently many websites are slow to display their text. Usually, the background, images and so on are going to be loaded, but no text. After...

  • 发布于 2021-04-11 21:33
  • 阅读 ( 142 )

初学者极客:如何开始使用键盘快捷键

...键,但每个电脑用户都能从中受益。 关于键盘快捷键的网页通常会给新用户提供一长串快捷键。我们将帮助您轻松使用键盘快捷键,演示您应该开始使用的最有用的快捷键。 浏览器提示 大多数人不知道的最基本的键盘快捷键...

  • 发布于 2021-04-12 00:16
  • 阅读 ( 160 )

如何节省墨水,使网站打印效果更好

打印出你想要硬拷贝的网页可能会有点走投无路。与其他文件不同的是,要准确地说出需要多少张纸,以及是否会有任何尴尬的剪辑并不容易。再加上打印不需要的图像和广告浪费墨水的问题,难怪许多人会选择复制和粘贴到...

  • 发布于 2021-04-12 01:49
  • 阅读 ( 188 )

使用有线标记在线突出显示文本

...除此标记。 这一切都是好的,但如果我们只是突出这些网页,我们如何找到他们呢?好吧,考虑到保持页面缓存的能力,你不再需要为所有你想要的信息添加书签,所以你也不想这么做。要找到突出显示的内容,只需按Alt+X,...

  • 发布于 2021-04-14 05:59
  • 阅读 ( 78 )

超文本(hypertext)和超链接(hyperlink)的区别

...接对照表什么是超文本(hypertext)?超文本是出现在文档或网页中的特殊文本。它将该文档或网页链接到另一个信息页面或数据。它是万维网的重要组成部分,是连接万维网上所有网页的媒介。它是一种可立即访问的文本,使用超...

  • 发布于 2021-07-11 16:07
  • 阅读 ( 172 )
纪Dark往人
纪Dark往人

0 篇文章

相关推荐