1

I want to write a basic script that can function as a dependency manager like RequireJS (but not as complex).

Ideally, like RequireJS, I'd like to be able to call a function, and give the function an array of scripts to load and a callback to call when the scripts are finished loading. I'm thinking of something like the following:

myRequireFunc(['scriptA', 'scriptB', 'scriptC'], function () {
  // Callback code here
});

Following the following SO thread, I was able to make some progress with dynamically loading scripts and then calling a callback when they're all loaded, but the issue I'm having now is what to do when scriptA, scriptB or scriptC has a dependency of its own:
Dynamically load external javascript file, and wait for it to load - without using JQuery

Can anyone please offer some advice/direction on how to handle dependencies so that a call to myRequireFunc will not call the callback until all scripts and all dependencies of those scripts have loaded?

Community
  • 1
  • 1
HartleySan
  • 7,404
  • 14
  • 66
  • 119
  • 1
    What's wrong with requirejs itself? – Pointy Dec 05 '13 at 21:02
  • You need to build a transitive dependency graph, collapse it, and build the complete list. – Dave Newton Dec 05 '13 at 21:06
  • 1
    Pointy, there's nothing wrong with RequireJS. It's great, actually. More than anything, I was just trying to walk myself through the process to learn. Also, Dave Newton, I apologize, but I cannot understand your answer. Could you please elaborate a bit more? Thank you. – HartleySan Dec 05 '13 at 21:09
  • did you check yepnopejs for solution? – paka Dec 05 '13 at 21:57

0 Answers0