Load external javascript based on current URL



We have close to 1000 pages and have a need to place 2 javascript across these pages.

The issue: the 2 javascript files can not be loaded on the same page or it will cause issues with our backend.

I found this script:

  // Script will NOT fire on URLs containing "check"
  // Change the below variable to look for a different string in the URL (You can add an entire URL)
  var excludeFromSM = "check";
  if (document.location.href.indexOf(excludeFromSM) === -1){ 
    // Your code goes here

I set that variable excludeFromSM as an array and loaded about 100 urls.

var excludeFromSM = ["list", "of", "websites"];

I’m not sure if that even works because I keep getting “Uncaught SyntaxError: Unexpected token (” in my console.

Also, how would I get it to load an external javascript file? I know document.write wouldn’t work in this case as it would load the script after everything else has loaded, I believe. Please help. Thanks!