Last active
March 4, 2020 23:22
-
-
Save thawkin3/78534ce6be2125a3ad3e0b780bff21cc to your computer and use it in GitHub Desktop.
Using a dynamic import to lazy load some JS
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
const exportPdfButton = document.querySelector('.exportPdfButton') | |
exportPdfButton.addEventListener('click', () => { | |
import('./pdf-download.js') | |
.then(module => { | |
// call some exported method in the module | |
module.exportPdf() | |
}) | |
.catch(err => { | |
// handle the error if the module fails to load | |
}) | |
}) | |
// the 'pdf-download.js' module is only imported once the user click the "Export PDF" button |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment