Are LINK elements loaded synchronously?

本秂侑毒 提交于 2019-12-12 11:23:12

问题


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>

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

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.


回答1:


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

However,

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

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



来源:https://stackoverflow.com/questions/12371080/are-link-elements-loaded-synchronously

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!