modulepreload-in-early-hints.html (968B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="early-hints-helpers.sub.js"></script> 6 <body> 7 <script> 8 async function fetchModuleScript(url) { 9 return new Promise((resolve, reject) => { 10 const el = document.createElement("script"); 11 el.src = url; 12 el.type = "module"; 13 el.onload = resolve; 14 el.onerror = _ => reject(new Error("Failed to fetch resource: " + url)); 15 document.body.appendChild(el); 16 }); 17 } 18 19 const params = new URLSearchParams(window.location.search); 20 const description = params.get("description"); 21 22 promise_test(async (t) => { 23 const resource_url = params.get("resource-url"); 24 const should_preload = params.get("should-preload") === "true"; 25 await fetchModuleScript(resource_url); 26 assert_equals(isPreloadedByEarlyHints(resource_url), should_preload); 27 }, description); 28 </script> 29 </body>