Skip to content

Instantly share code, notes, and snippets.

@fcamblor
Last active August 17, 2022 07:59
Show Gist options
  • Save fcamblor/cf2abad2afcc0edb9bcec40ed3cf57cd to your computer and use it in GitHub Desktop.
Save fcamblor/cf2abad2afcc0edb9bcec40ed3cf57cd to your computer and use it in GitHub Desktop.
debug-requirejs-loading.js

Simply include debug-requirejs-loading.js script before starting your requirejs dependencies :

<script src="scripts/require.js"></script>
<script src="path/to/debug-requirejs-loading.js"></script>
<script type="text/javascript">
require(['data/main'], function(){ console.log("requirejs started !"); });
</script>

It will show :

  • define() definition calls ordering (you can browse/search it through window.__requirejsDebug.defined array at any moment)
  • define() ready function calls ordering (which will depend on your require() calls). You can browse/search throught window.__requirejsDebug.ready array at any moment.
window.__requirejsDebug = {
defined: [],
ready: []
};
var __oldDefine = define;
define = function(moduleName, deps, ready) {
console.log("Calling define() with arguments : ", arguments);
window.__requirejsDebug.defined.push(arguments);
if(!_.isFunction(ready)) {
ready = deps;
deps = null;
}
return __oldDefine(moduleName, deps, function() {
console.log(moduleName+" is READY !");
window.__requirejsDebug.ready.push(arguments);
return ready.apply(this, arguments);
});
};
// Copying properties otherwise we will loose stuff like define.amd property (which may be used in
// js scripts like ua-parser-js)
for(var definePropName in __oldDefine) {
define[definePropName] = __oldDefine[definePropName];
}
@amine-y
Copy link

amine-y commented Aug 17, 2022

Thanks a lot for that script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment