const JS_URL = "https://solvefit-web-ui.ben-457.workers.dev/plugin.js"; document.addEventListener("DOMContentLoaded", function() { if(JS_URL && JS_URL.length > 0) { $.getScript(JS_URL) .done(function( script, textStatus ) { // DO NOTHING - the script has been loaded successfully }) .fail(function( jqxhr, settings, exception ) { $.getScript("/js/plugin.js.php"); }); } });