Last active
May 23, 2019 16:47
-
-
Save iggyvolz/aab783b8c4a081ccd1ec590a3f4c30cb to your computer and use it in GitHub Desktop.
Firefox preload polyfill for Link headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/yoavweiss/b1f798bb2be4e671107b#file-preload_feature_detection-js | |
const supportsPreload = (function() { | |
try { | |
return document.createElement("link").relList.supports('preload'); | |
} catch (e) { | |
return false; | |
} | |
}()); | |
if (supportsPreload) { | |
console.log("Supports preload"); | |
}else{ | |
fetch(window.location, { | |
method: "HEAD" | |
}).then(x => { | |
const headers=Array.from(x.headers).filter(x=>x[0]==="link").map(x=>x[1]); | |
headers.forEach(header=>{ | |
const file=/^<([^>]+)>/.exec(header)[1]; | |
fetch(file); | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment