How to force a script reload and re-execute?

How about adding a new script tag to <head> with the script to (re)load? Something like below:

<script>
   function load_js()
   {
      var head= document.getElementsByTagName('head')[0];
      var script= document.createElement('script');
      script.src="https://stackoverflow.com/questions/9642205/source_file.js";
      head.appendChild(script);
   }
   load_js();
</script>

The main point is inserting a new script tag — you can remove the old one without consequence. You may need to add a timestamp to the query string if you have caching issues.

Leave a Comment

tech