Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>"Loaded" is a bit vague word. </p> <p>If it means the request is made for the module. its specified. as soon as a the module is required anywhere, either as a dependency of a module definition or a require call with the module name, following returns true.</p> <pre><code>require.specified(moduleID); </code></pre> <p>Once the module is resolved and is loaded in memory, or in other words once the module's source is fetched and loaded and the module's definition function is finished execution. following returns true.</p> <pre><code>require.defined(moduleID); </code></pre> <p>you can also look it up in <code>requirejs.s.contexts._.defined</code>. It's a bit of a hackish way to inspect the data structure of a lib like this, but works in browser (firebug) in case you want to insure a module is loaded or not. I have tested following with firebug and requirejs 2.1.4.</p> <pre><code>console.log(window.requirejs.s.contexts._.defined['SOME_MODULE']); </code></pre> <p>this method also helps in inspecting the inner content (properties of object/prototype) of modules with firebug. </p> <p>if requirement is to ensure that a critical module loaded before executing the code further. the require call with a success callback works.</p> <pre><code>require([moduleID], function(moduleExport){ //The module is loaded, proceed to the next step //This is also an inherent load check }, function (error) { //The module cant be loaded, handle the exception case }); </code></pre> <p>Following snippet shows every one of above</p> <pre><code>console.log(require.specified('TEST_MODULE')); //false if the module isn't required yet require(['TEST_MODULE'], function(TEST_MODULE){ console.log(require.defined('TEST_MODULE')); //true console.log(require.s.contexts._.defined['TEST_MODULE'] ? true : false); //true }, function (error) { console.log('TEST_MODULE cant be loaded'); }); console.log(require.defined('TEST_MODULE')); //false if the module isn't ready yet console.log(require.specified('TEST_MODULE')); //true </code></pre> <p>** requirejs can be used instead of require in case require is used for some other purpose in global scope. </p> <p>** All of the above assumes that you have a reference to require/requirejs [global] wherever you are testing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload