-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested/Hierarchy of head.js calls in multiples files doesn't work #231
Comments
You mean you want something like head.done('dependency', function() {
....
}); Which should be called when all dependencies of 'dependency' are done loading? |
I think this should be the default behavior. I can't think of any example where "dependency" can be considered done loading while none of its dependencies are done loading. If such an example exists, I would say that those dependencies aren't really dependencies! |
Well head.js doesn't use the notion of dependency actually like you interpret it. I know what you want, but that functionality is more something of require.js, not that of head.js IMHO 😄 |
Actually, require.js doesn't do it either. Only LAB.js does this properly. requirejs/requirejs#710 |
Oh ok, i just assumed so because of its name, i don't use either 😄 Just keep in mind that head.ready() is not the same as a "Include <xxx.h>", "require <xxx.cpp>" or similar directive in other languages that get compiled... |
Btw, I'm using It seems very weird to me. In every other language (take Ruby for example), if you I expect script loaders that have any concept of "run this before that" (which head.js does) would respect this simple order that exists elsewhere. I guess I can hack something together with |
Well thats because those language provide those mechanisms as part of their structured language, while Javascript does not.... When you make use of head.ready('someid', function(){
head.feature('a_loaded', true);
});
head.ready('someid', function(){
head.feature('b_loaded', true);
});
(function(){// To prevent global name polution.
(function areWeDone(){
if(head.a_loaded && head.b_loaded){
do your stuff
or load more with head.js()
}else{
window.setTimeout(areWeDone,50);// This delays and re-calls our loop.
}
})();// define+execute
})(); You could ofcourse also use your own global-object with properties instead of |
Ohh ps. |
Is there any way to have multiple files in I think CommonJS' Thanks for the code - if any of the files fail to load (e.g. 404) the timeout will repeat forever though. |
You better refer to the documentation at: http://headjs.com/#api About the infinite looping on not-found (404), that will ofcourse happen with the above code 😄 |
I've read the docs. I guess it's impossible to declare multiple files within a head.ready. Workaround seems to be to nest the head.ready calls. On the bright side, the dependencies seem to be resolving properly! For posterity, code looks like: head.js('a.js', 'b.js', 'c.js');
head('b.js', function () {
head('c.js', function () {
// Code 1
});
}); And in head('a.js', function () {
// Code 2
}); And the order of execution will be correct! Thanks for your patience! |
np yw 😺 |
See http://jsfiddle.net/TWDy4/ for a simple example of the bug. Here's the situation:
Currently, as soon as my direct dependencies are loaded, my
complete
callback runs. The problem is that I need mycomplete
callback to wait for the dependencies of my dependencies to load, and for my dependencies to run theircomplete
callbacks. In other words, mycomplete
callback should run last.In headjs, my app code currently runs as soon as its direct dependencies are fulfilled; but it should wait until its indirect dependencies are fulfilled, too. The only solution right now is to add my dependencies' dependencies to my list of dependencies - but I shouldn't have to know anything about my dependencies' dependencies.
The text was updated successfully, but these errors were encountered: