I have recently been tasked with cleanup of our GTM tags. I notice that a lot of the tags include remote scripts by injecting them into the DOM using JS, for example:
var head = document.getElementsByTagName('head')[0]
var js = document.createElement('script');
js.src = 'https://cdn.somewhere.com/script.js';
head.appendChild(js);
Is there a specific reason why people do it this way instead of just using this?
<script type="text/javascript" src="https://cdn.somewhere.com/script.js" async></script>
What are the benefits of doing it the first way? Is there a better way to handle external scripts?