Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>fetchpriority</title>
</head>
<body>
<script>
onload = function() {
const kData = [
{ href: "../resources/dummy.css?1", fetchPriority: "low", isAlternate: false,
isMediaPrint: false },
{ href: "../resources/dummy.css?2", fetchPriority: "high", isAlternate: false,
isMediaPrint: false },
{ href: "../resources/dummy.css?3", fetchPriority: "auto", isAlternate: false,
isMediaPrint: false } ,
{ href: "../resources/dummy.css?4", isAlternate: false,
isMediaPrint: false } ,
{ href: "../resources/dummy.css?5", fetchPriority: "low", isAlternate: true,
isMediaPrint: false, title: "5" },
{ href: "../resources/dummy.css?6", fetchPriority: "high", isAlternate: true,
isMediaPrint: false, title: "6" },
{ href: "../resources/dummy.css?7", fetchPriority: "auto", isAlternate: true,
isMediaPrint: false, title: "7" },
{ href: "../resources/dummy.css?8", isAlternate: true,
isMediaPrint: false, title: "8" },
{ href: "../resources/dummy.css?9", fetchPriority: "low", isAlternate: false,
isMediaPrint: true },
{ href: "../resources/dummy.css?10", fetchPriority: "high", isAlternate: false,
isMediaPrint: true },
{ href: "../resources/dummy.css?11", fetchPriority: "auto", isAlternate: false,
isMediaPrint: true },
{ href: "../resources/dummy.css?12", isAlternate: false,
isMediaPrint: true },
];
let loadCounter = 0;
let allLinkElements = [];
for (data of kData) {
let linkElement = document.createElement("link");
linkElement.rel = data.isAlternate ? "alternate stylesheet" :
"stylesheet";
if (data.isAlternate) {
linkElement.title = data.title;
}
linkElement.href = data.href;
// Wait until all elements have been loaded.
linkElement.onload = () => {
++loadCounter;
if (loadCounter == allLinkElements.length) {
opener.postMessage("ChildLoaded", "*");
}
}
if ("fetchPriority" in data) {
linkElement.fetchPriority = data.fetchPriority;
}
if (data.isMediaPrint) {
linkElement.media = "print";
}
allLinkElements.push(linkElement);
}
document.head.append(...allLinkElements)
}
</script>
</body>
</html>