Skip to content

Instantly share code, notes, and snippets.

@iggyvolz
Last active May 23, 2019 16:47
Show Gist options
  • Save iggyvolz/aab783b8c4a081ccd1ec590a3f4c30cb to your computer and use it in GitHub Desktop.
Save iggyvolz/aab783b8c4a081ccd1ec590a3f4c30cb to your computer and use it in GitHub Desktop.
Firefox preload polyfill for Link headers
// 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