1
Hello, I have a question regarding the loading of a Javascript library. I am to build an application that builds components with reuse practicality, and for that the structure of each component would be being created like this:
//componente foo
.foo = {
style : "foo.css",
template : "foo.html",
script : "script.js",
"imgDir" : "img",
//etc...
};
Thinking of a logic to facilitate the maintenance and reuse of these components, and also in the class system of a heavily typed application I have the interest of including all the dependencies of the scripts of this component in the same component, so, if such a script was not loaded before, it should be for only then the system.
I got this idea to prevent loading the same library from the require_once
PHP. Is there any way I can force the DOM to see if the script already exists on the page so it doesn’t duplicate its link? It already occurred to me this at another time and ended up that the new insertion of Jquery kind of locked my application, because it was recreating the contents of a library inside the document and with that I lost instances and methods already declared and in use.
"with this I lost instances and methods already declared and in use", this is not true. It is impossible to lose an instance in use. When an instance is in use, its constructor will still exist because there is possibility of it being used, it is automatically deleted by the browser when it is dropped and can no longer be used. Just because the constructor of an instance is declared in a variable, property of an object or expression, etc., does not mean that it will disappear from nothing; functions/objects are not primitive values, and to be accessed they are 'referenced'.
– Klaider
if in you have in a library something like
window.foo = new foo()
it will disappear with everything that has already been manipulated or inserted inside a prototype– LeandroLuk
It will disappear, but it will still exist, IE you "no" will lose instances, and you will not lose what is in the prototype
– Klaider