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 :)