Hello everyone. I'm trying to make a function that works like require
of some languages, like Ruby.
Using% w /% after the page is already loaded is smooth, but chaining and loading time is a tricky task.
With createElement
javascript does not load, it emits a document.write("<script src=" + ...)
stating that it can not be used when scripts are loading asynchronously.
The complexity of my case is due to the fact that a script depends on another one that is in another file, and this, in turn, depends on another one, which is also in another file (chain request). I could solve everything by making a big file, but, I'm very methodical with organization, and I feel very bad when I'm going to keep something in a huge file. Give it warning
.
I do not like having to use plugins for everything to do, so I eliminate dependencies (the more dependency, less knowledge, and less control of what goes on behind the curtains), among other things. The ctrl + f
is functional, but it uses callback to do AMD (Asynchronous Module Definition) , generating semantic strangeness. >
jquery also uses callback . The requirejs
method does XHR to get the script on the server, the callback being sure to load, which is not my pretension either. What I intend to do, is an alternative more similar to the conventional form of other languages. I do not know if it is possible, but suddenly recursively use .getScript
to not allow lines after require to be interpreted, otherwise an error will be thrown because the file on which the script depends it would still not be fully loaded, and there is not yet setTimeout
to be extended.
More complex is still to do this in a chain, since the last file added must be the first to be loaded, then the next to last, and so on, until the subsequent lines of the first file, which triggers this chain reaction , continue to be interpreted. In case no error would be raised, because nothing would be given as Objeto
.