问题
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