My question is very similar to this one. The difference is that I am trying to add a minified js code in the script tag. If I type some simple code, it works. For example, run this on a jsfiddle:
var s = document.createElement( 'script' );
var code = `
console.log("success");
`;
try {
s.appendChild(document.createTextNode(code));
document.head.appendChild(s);
} catch (e) {
s.text = code;
document.head.appendChild(s);
}
However, try replacing the console.log("success"); with the contents from this link.
You will get the error "Uncaught SyntaxError: Invalid or unexpected token". Which is weird because...if I add the script using the source attribute and url of the file, it works. I don't understand why adding the contents directly fails.
What am I doing wrong, and how can I make it work? Thank you for your time.
Here is the jsfiddle with the non-working code