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

130
Visualizações
Include library like jQuery only if needed and used in somewhere

Something is in my mind but don't know how to implement it. Is it really implementable?

jQuery is not included in whole website. When it is used in some files, it will return an error that $ or jQuery is not defined and here is what I want to do. I want to make something like try/catch in a app.js/root.js/parent.js/index.js (or any other file.js that is accessible from other js files or we can call it the parent of other js files) in order to get all throws and if the type of the throw (which is thrown from a child) is related to jQuery or $ then include jQuery in the file that had called it. Is it possible?

child.js

$(document).html('test');

It is not defined so that, it throws an undefined error.

and here (that I don't know how) to catch the error

index.js (app.js / root.js / parent.js and any file that is accessible by any other js file)

if(typeof error == 'jquery not defined') {
    window.$ = window.jQuery = require('jquery')
}

and then the window.$ should be returned to the caller in order to use it.

Thank you :)

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