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?

4
  • 1
    What's wrong with requirejs itself? Commented Dec 5, 2013 at 21:02
  • You need to build a transitive dependency graph, collapse it, and build the complete list. Commented Dec 5, 2013 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. Commented Dec 5, 2013 at 21:09
  • did you check yepnopejs for solution? Commented Dec 5, 2013 at 21:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.