Created
March 19, 2024 15:49
-
-
Save neopunisher/4e56d2c5874852bca8652d786a67b7b8 to your computer and use it in GitHub Desktop.
Dynamic importmap
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
if (HTMLScriptElement.supports && HTMLScriptElement.supports('importmap')) { | |
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap | |
const importMap = { | |
imports: { | |
lazyload: 'IntersectionObserver' in window | |
? './lazyload.js' | |
: './lazyload-fallback.js', | |
}, | |
}; | |
const im = document.createElement('script'); | |
im.type = 'importmap'; | |
im.textContent = JSON.stringify(importMap); | |
document.currentScript.after(im); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment