Skip to content

Instantly share code, notes, and snippets.

@dman777
Created July 8, 2023 21:13
Show Gist options
  • Save dman777/6b827c900b6f38c0d877392fcb0ad0f6 to your computer and use it in GitHub Desktop.
Save dman777/6b827c900b6f38c0d877392fcb0ad0f6 to your computer and use it in GitHub Desktop.
#downloadJSPdf() {
const loadJspdf = (() => {
async function actuallyLoad() {
const script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js';
await new Promise((resolve, reject) => {
script.addEventListener('error', reject);
script.addEventListener('load', resolve);
document.head.appendChild(script);
});
}
let loadingPromise;
return async () => {
if (loadingPromise === undefined) {
loadingPromise = actuallyLoad();
}
return loadingPromise;
};
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment