Created
December 29, 2020 21:28
-
-
Save tsmd/db8fbd844a375c588e346ae0249b7dad to your computer and use it in GitHub Desktop.
Load polyfills conditionally from CDN
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Load polyfills conditionally from CDN</title> | |
<script> | |
function loadFromCdn(src, integrity) { | |
var s = document.createElement("script"); | |
s.src = src; | |
s.integrity = integrity; | |
s.crossOrigin = "anonymous"; | |
s.defer = true; | |
document.head.appendChild(s); | |
} | |
</script> | |
<script> | |
if (!("inert" in document.documentElement)) { | |
loadFromCdn( | |
"https://cdn.jsdelivr.net/npm/wicg-inert@3.1.0/dist/inert.min.js", | |
"sha256-s9GW1xPpeQvxawx/zhbu0eP+RPJMNl5JiHgDeeVKYJ8=" | |
); | |
} | |
</script> | |
<script> | |
try { | |
document.querySelector(":focus-visible"); | |
} catch (e) { | |
loadFromCdn( | |
"https://cdn.jsdelivr.net/npm/focus-visible@5.2.0/dist/focus-visible.min.js", | |
"sha256-ar5bSkVmDS4cGm9DnZltimmnoaRyvhacMSGt5Re3qwU=" | |
); | |
} | |
</script> | |
<script> | |
if (!window.HTMLPictureElement) { | |
loadFromCdn( | |
"https://cdn.jsdelivr.net/npm/picturefill@3.0.3/dist/picturefill.min.js", | |
"sha256-iT+n/otuaeKCgxnASny7bxKeqCDbaV1M7VdX1ZRQtqg=" | |
); | |
} | |
</script> | |
<script> | |
if (!("objectFit" in document.documentElement.style)) { | |
loadFromCdn( | |
"https://cdn.jsdelivr.net/npm/object-fit-images@3.2.4/dist/ofi.min.js", | |
"sha256-NyF8/ts5NW0qD9MX5Kjuh9Il9DZOOvx0c6tajn2X7GQ=" | |
); | |
} | |
</script> | |
</head> | |
<body> | |
Hello, world! | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment