Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda