javascript - DOMContentLoaded 是否等待网络字体 (Firefox)?

标签 javascript webfonts google-webfonts domcontentloaded

我在应用程序中使用 Google 的网络字体,我注意到 DOMContentLoaded 在下载网络字体之前似乎不会在 Firefox 中触发。我做错了什么还是这是预期的行为?

我的字体包含在 head 部分的类似内容中:

<link href="http://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">

我的 JavaScript 链接在我的页面底部,并添加了一个事件,如下所示:

document.addEventListener('DOMContentLoaded', function() {
  ...do stuff...
})

我尝试在 Chrome 上对此进行测试,但无法真正确定它发生的顺序(字体加载速度如此之快)。

最佳答案

根据 Mozilla 的 documentationDOMContentLoaded :

Note: Stylesheet loads block script execution, so if you have a <script> after a <link rel="stylesheet" ...>, the page will not finish parsing - and DOMContentLoaded will not fire - until the stylesheet is loaded.

因此,您似乎遇到了预期的行为 DOMContentLoaded直到您的外部网络字体完全下载后才会触发。

关于javascript - DOMContentLoaded 是否等待网络字体 (Firefox)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25223470/

相关文章:

javascript - Google Web 字体在 OSX Safari 中不显示,但在 Firefox、Chrome、Opera(适用于 OSX、Windows 和 Linux)和 Internet Explorer 中显示

html - Google Web 字体在 IE8 中不工作

javascript - 选中时更改标签颜色单选

javascript - 如何仅通过javascript显示带参数的iframe

javascript - 如何在 JavaScript 中从代理对构造 UTF-16 字符?

css - @font-face 在文件夹中找不到字体

html - 如何设置字体数据: in a Content Security Policy meta tag?

javascript - 使用 Javascript 为整个 session 加载网站字体

css - 字形 š 总是粗体

javascript - HTML5 音频 - 无效状态错误(或 Dom 异常 11)测试