How to properly load scripts inside resize event listener?

The problem is that when resizing the page is causes the script to not load properly. My guess is it tries to load them again. In other words, resizing the page causes to load the content like if scripts were never set. Should I set a function to reload the scripts on window resize? But I suppose that wouldn’t be very performant.

window.addEventListener("resize", getTemplate);

CurrentPage = 'MobilePage';

function getTemplate() {
    if (screen.width >= 767 && CurrentPage != 'DesktopPage') {
	// fetch contents 
         fetch('<?php bloginfo('template_url'); ?>/portafolio-desktop-slider.php')
          .then(response => response.text())          
          .then( resultText => document.getElementById('example').innerHTML = resultText          );
	//call the scripts

 	  var head = document.getElementsByTagName('head')[0];
          var body = document.getElementsByTagName('body')[0];

          var VueScript = document.createElement("script");
          VueScript.src = "url";
          VueScript.async = false;
          head.appendChild(VueScript);

Edit: perhaps with this: EventTarget.removeEventListener() - Web APIs | MDN