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 = [
{ src: "../resources/dummy.js?1", fetchPriority: "low", svg: false},
{ src: "../resources/dummy.js?2", fetchPriority: "high", svg: false},
{ src: "../resources/dummy.js?3", fetchPriority: "auto", svg: false},
{ src: "../resources/dummy.js?4", svg: false},
{ src: "../resources/dummy.js?5", fetchPriority: "low", svg: true},
{ src: "../resources/dummy.js?6", fetchPriority: "high", svg: true},
{ src: "../resources/dummy.js?7", fetchPriority: "auto", svg: true},
{ src: "../resources/dummy.js?8", svg: true},
];
let allScriptElements = [];
for (data of kData) {
if (!data.svg) {
scriptElement = document.createElement("script");
scriptElement.src = data.src;
if ("fetchPriority" in data) {
scriptElement.fetchPriority = data.fetchPriority;
}
} else {
const namespaceURI = "http://www.w3.org/2000/svg";
scriptElement = document.createElementNS(namespaceURI, "script");
scriptElement.href.baseVal = data.src;
// Use setAttribute as SVGScriptElement has no fetchPriority property.
if ("fetchPriority" in data) {
scriptElement.setAttribute("fetchPriority", data.fetchPriority);
}
}
scriptElement.type = "module";
if ("fetchPriority" in data) {
scriptElement.fetchPriority = data.fetchPriority;
}
allScriptElements.push(scriptElement);
}
document.head.append(...allScriptElements)
opener.postMessage("ChildLoaded", "*");
}
</script>
</body>
</html>