Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!