add script in head tag using javascript file code example
Example 1: how to add script in html head
<script src="script.js" defer></script>
<!--just add defer attribute so script will execute at last-->
Example 2: javascript add script in head programmatically
var my_awesome_script = document.createElement('script');
my_awesome_script.setAttribute('src','http://example.com/site.js');
document.head.appendChild(my_awesome_script);