AMD Spec Enhancement: onResourceLoad

Skip to first unread message


Jun 13, 2013, 1:07:32 AM6/13/13
I'm not sure where or how to best discuss this, but I'd like to propose a new feature as part of the AMD specification. In require.js there is a "private" hook called onResourceLoad. By supplying a function require.js will call you back each time it completes the loading of a module (or any resource for that matter). It provides contextual information, the module id and access to the defined module, more or less.

As it turns out, having a hook like this is very powerful if you are building a framework or AMD-based tooling. It opens up a bunch of interesting possibilities. A few examples are: convention based coding via module id and module relationships, aspect oriented programming via altering modules after they are defined, logging, automatic pub/sub between modules, etc.

The hook should be fairly trivial in most loaders. require.js already has it. I forked almond and was able to add it in a minute or two with only 4 lines of code. There is also a pull request for dojo which adds a similar hook.

Given the low amount of effort, small overhead, and extensive possibilities this opens up, I think it is worth seriously considering as an addition to the spec.

How shall we proceed?

James Burke

Jun 14, 2013, 7:00:47 PM6/14/13
I would like see us try to work out if we can start adopting the ES
Module Loader APIs as that will transition better to ES land:

That spec is still under construction, but is up to date with their
latest thinking.

I am hoping to start prototyping with it just to see if we can adapt
it for AMD code. I think it has some weaknesses though still. For
instance, their normalize hook probably needs to allow for async
return so we can load a loader plugin to finish the normalization.

But also, for your use case, if you can see how it could meet your
needs that may be useful feedback to give to the ES folks that are
working on that spec.

Another first pass on this would be just for other loader implementers
to list out any related calls to what you describe, to see if there is
emergent common ground.

> --
> You received this message because you are subscribed to the Google Groups
> "amd-implement" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
> For more options, visit


Jun 15, 2013, 5:34:14 PM6/15/13
That sounds excellent. Obviously it would be great to have this kind of thing available as part of the ES Module Loader....and I've love to have a smooth transition from current libraries into the new ES stuff. How can I help in the process?

James Burke

Jun 16, 2013, 8:29:11 PM6/16/13
Reading the draft specs might be a place to start. That is how I am starting, and trying to make some code along those lines. Nothing concrete yet though.

Reply all
Reply to author
0 new messages