How can I keep track of what scripts have been loaded so far so I can display a progress bar when using labjs (http://labjs.com/)? wait()
doesn't work because then it won't parallel load the next resource. Basically i'm looking for some kind of non-blocking callback function i can tie into. Does this exists in labjs?

- 7,953
- 19
- 62
- 119
1 Answers
wait()
does not affect the parallel loading of LABjs... it will always parallel load as much as possible (allowed by the browser).wait()
only affects the execution of scripts. If it's inserted between twoscript()
calls, it ensures that the second script will "wait" for the first script to finish executing before it executes.No, there is no exposed API for the load-finishing on scripts, because browsers do not expose a consistent API for when a script finishes loading (only when it executes: "onload", as confusing as that name is).
Now, you can do a progress meter using wait()
calls in between each script, but it will tell you something slightly different than what you asked: what percentage of the scripts have executed, not what percentage of the scripts have downloaded. Depending on your needs, that might be quite acceptable.

- 15,725
- 2
- 33
- 55
-
@LordZardeck depends on what you mean by "affects performance". `wait()` does not affect the performance of parallel downloads. however, if you use a `wait()` to delay the execution of a critical piece of code, and something before the `wait()` is slow to load or run, then the critical code will be delayed (obviously), and this will definitely affect "perceived" performance. Rule of thumb: only make a piece of code wait to execute if it really needs to wait. if it can run independently, either leave off the `wait()` that holds it up, or use a separate $LAB chain. – Kyle Simpson Jun 06 '12 at 20:48