LINK元素是否同步加载? [英] Are LINK elements loaded synchronously?

查看:143
本文介绍了LINK元素是否同步加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有以下HTML5文档:

If I have the following HTML5 document:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>FOOBAR</title>
</head>
<body>
<link rel="stylesheet" href="/largefonts.css">
<script src="onload.js"></script>
</body>
</html>

< link> 标记是否会加载同步,所以当执行 onload.js 脚本时,应该在浏览器中加载字体?

Will the <link> tag load synchronously, so that when the onload.js script is executed, the fonts should be loaded in the browser?

请注意,我不是要求字体应用到任何DOM节点,我只想知道它们是否已加载到内存中。

Note that I’m not asking if the fonts have been applied to any DOM nodes, I just want to know if they are loaded into memory.

推荐答案

< link> 资源的过程.org / specs / web-apps / current-work / multipage / semantics.html#concept-link-obtainrel =nofollow> HTML5规范的相应部分,答案如下:

The process for obtaining <link> resources is described in the corresponding section of the HTML5 spec, and answers like this:


用户代理可能选择仅在需要时尝试获取此类资源,而不是主动获取所有资源未应用的外部资源

User agents may opt to only try to obtain such resources when they are needed, instead of pro-actively fetching all the external resources that are not applied

然而,


[< link& gt; ]元素必须延迟元素文档的load事件,直到所有获取资源及其关键子资源的尝试都完成为止

The [<link>] element must delay the load event of the element's document until all the attempts to obtain the resource and its critical subresources are complete

...意味着文件的加载事件在所有< link> 之前都不会触发s已加载(或失败)

…meaning that a document's load event won't fire until all <link>s have been loaded (or failed)

这篇关于LINK元素是否同步加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆