1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// load 'src' from CDN if it isn't already
// callback is a string that defines a function you'd like to run after your script loads
export function addScript(src: string, callback?: Function): string {
return `
<script type="text/javascript">
// check if the script tag already exists
const script = const scriptTag = document.querySelector(script[src="${src}]);;
// if the script tag does not exist, add it to the document
if (!script) {
var script = document.createElement('script');
script.src = '${src}';
document.head.appendChild(script);
}
</script>
`;
}