How do I reinit WordPress plugins dynamically using jS?

Figured it out, for anyone else who runs into this issue here is the top to bottom of it. The plugin itself was using DOMContentLoaded (as pointed out by @JacobPeattie), in the initialisation script of the plugin.

So I created a clone of the initialisation script without the DOMContentLoaded function wrapper and dumped it on the server in a permanent folder under a different file name (reinitPlugin.js).

Then when reinitGallery(); was fired from the Barba.js transition, I removed the CSS and jS from the DOM using .remove() and reappended the core style and script tags only on the page where the plugin content needed to be rendered (/gallery).

Simply doing the same ‘swap/replacement’ with the initialisation script didn’t work correctly, no console errors it just didn’t fire at all, the file itself was updated in the DOM just no dice. Due to Barba.js being PJAX, I decided to try an .ajax() function to load the script instead and to wrap it in setTimeout() to ensure it loaded after the other scripts had been rendered and voilĂ .

Working Code:

function reInitGallery() {
    jQuery("#plugin-css").remove();
    jQuery("#plugin-js").remove();
    jQuery("#plugin-js-after").remove();
    if (window.location.href.indexOf("gallery") > -1) {
      // reinit css
      jQuery('head').append('<link rel="stylesheet" id="plugin-css" href="/plugins/plugin/css/plugin.css" type="text/css" media="all" />');
      // reinit js
      var pluginReplacementScript = document.createElement('script');
      fwds3dcovReplacementScript.type="text/javascript";
      fwds3dcovReplacementScript.id = 'plugin-js';
      fwds3dcovReplacementScript.src="https://wordpress.stackexchange.com/wp-content/plugins/plugin/js/plugin.js";    
      document.body.appendChild(pluginReplacementScript);
      // reinit js after
      setTimeout(function() {
        jQuery.ajax({
          url: '/wp-content/plugins/plugin/js/reinitPlugin.js',
          dataType: "script"
        });
      }, 300);
    }
}