Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
How can I add a minified js script to the dom and execute it?

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

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda