Skip to content

Commit

Permalink
Simply load code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian committed Nov 8, 2024
1 parent f77704c commit e41c9bf
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ sampleRUM('cwv');

async function loadBodyScript(src, attrs) {
return new Promise((resolve, reject) => {
if (!document.querySelector(`body > script[src="${src}"]`)) {
const script = document.createElement('script');
script.text = src;
if (attrs) {
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const attr in attrs) {
script.setAttribute(attr, attrs[attr]);
}
const script = document.createElement('script');
script.text = src;
if (attrs) {
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const attr in attrs) {
script.setAttribute(attr, attrs[attr]);
}
script.onload = resolve;
script.onerror = reject;
document.body.append(script);
} else {
resolve();
}
script.onload = resolve;
script.onerror = reject;
document.body.append(script);
});
}

Expand Down

0 comments on commit e41c9bf

Please sign in to comment.