Skip to content

Instantly share code, notes, and snippets.

@lili21
Forked from yoavweiss/preload_feature_detection.js
Created February 28, 2017 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lili21/1db98d837961e3c7916035d9904556c0 to your computer and use it in GitHub Desktop.
Save lili21/1db98d837961e3c7916035d9904556c0 to your computer and use it in GitHub Desktop.
Preload feature detection
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.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment