Last active
July 24, 2020 19:31
-
-
Save yoavweiss/b1f798bb2be4e671107b to your computer and use it in GitHub Desktop.
Preload feature detection
This file contains 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
var DOMTokenListSupports = function(tokenList, token) { | |
if (!tokenList || !tokenList.supports) { | |
return; | |
} | |
try { | |
return tokenList.supports(token); | |
} catch (e) { | |
if (e instanceof TypeError) { | |
console.log("The DOMTokenList doesn't have a supported tokens list"); | |
} else { | |
console.error("That shouldn't have happened"); | |
} | |
} | |
}; | |
var linkSupportsPreload = DOMTokenListSupports(document.createElement("link").relList, "preload"); | |
if (!linkSupportsPreload) { | |
// Dynamically load the things that relied on preload. | |
} |
@triblondon I think, better solution is: var supportsPreload = (function() { try { return document.createElement("link").relList.supports('preload'); } catch(e) { return false; }}());
https://github.com/filamentgroup/loadCSS/blob/master/src/cssrelpreload.js
Your code return false positive for FF 58.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you wanted to reduce the code bloat for production, would this do?