Skip to content

Commit 26f8d31

Browse files
musaleMnickiisebastienlevert
authored
Set scripts without getting the HTML from the DOM (#1656)
Co-authored-by: Nickii Miaro <[email protected]> Co-authored-by: Sébastien Levert <[email protected]>
1 parent 6c124f0 commit 26f8d31

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

packages/mgt/src/bundle/mgt-loader.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@
2525
function getScriptPath() {
2626
var scripts = document.getElementsByTagName('script');
2727
var path = scripts[scripts.length - 1].src.split('?')[0];
28-
var dir =
29-
path
30-
.split('/')
31-
.slice(0, -1)
32-
.join('/') + '/';
28+
var dir = path.split('/').slice(0, -1).join('/') + '/';
3329
return dir;
3430
}
3531

@@ -49,16 +45,14 @@
4945
}
5046

5147
function addScript(src, onload) {
52-
// TODO: support async loading
53-
5448
var tag = document.createElement('script');
55-
tag.src = src;
49+
tag.setAttribute('async', '');
50+
tag.setAttribute('src', encodeURI(src));
5651

5752
// if (onload) {
5853
// tag.addEventListener("load", onload);
5954
// }
6055

61-
document.write(tag.outerHTML);
62-
// document.head.appendChild(tag);
56+
document.head.appendChild(tag);
6357
}
6458
})();

0 commit comments

Comments
 (0)