Web Development14 Jan 2014 09:03 am
Simple Debug Logging for Require.JS
Figuring out load order issues in Require.JS can be a big pain some times. However, if you are using the non-minified version, its easy to add some instrumentation that makes things clear. The Require.JS code is well documented so feel free to look around. I find the following methods most helpful to instrument.
@@ -1517,10 +1517,11 @@ var requirejs, require, define; * A load event could be a script load or just a load pass from a synchronous * load call. * @param {String} moduleName the name of the module to potentially complete. */ completeLoad: function (moduleName) { + console.log('Completed load of ' + moduleName); var found, args, mod, shim = getOwn(config.shim, moduleName) || {}, shExports = shim.exports; takeGlobalQueue(); @@ -1635,10 +1635,11 @@ var requirejs, require, define; }, //Delegates to req.load. Broken out as a separate function to //allow overriding in the optimizer. load: function (id, url) { + console.log('Loading ' + id + ' from ' + url); req.load(context, id, url); }, /** * Executes a module callback function. Broken out as a separate function @@ -1646,10 +1647,11 @@ var requirejs, require, define; * layer in the right sequence. * * @private */ execCb: function (name, callback, args, exports) { + console.log('Initializing ' + name); return callback.apply(exports, args); }, /** * callback for script loads, used to check status of loading. |
F.Y.I. This diff was applied to Require.JS 2.1.10