Created
September 24, 2025 09:25
-
-
Save dragon-fish/9620734d6a77b80432b2cb103508dec8 to your computer and use it in GitHub Desktop.
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
| /** | |
| * @param {string} src | |
| * @param {Record<string, string>?} attrs | |
| * @returns {Promise<HTMLScriptElement>} | |
| */ | |
| function loadScript(src, attrs = {}) { | |
| return new Promise((res, rej) => { | |
| const s = Object.assign(document.createElement('script'), { src }) | |
| Object.entries(attrs).forEach(([k, v]) => k && v !== void 0 && s.setAttribute(k, v)) | |
| s.onload = () => res(s) | |
| s.onerror = (e) => rej(e) | |
| document.head.appendChild(s) | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment