Curl throwing "Promise an already completed bug

I am currently testing various asynchronous bootloader resources to find out which one I want to use. At the moment, Curl throws a Promise error already completed ... and their documentation says "this should never happen."

I suspect that I should use 'define in every uploaded file (hope not). In addition, their documentation says that Curl can work with javascript files other than AMD. But ... I'm new to AMD and with Curl much faster than the others that I'm testing ... I'm ready to work on understanding this better.

And finally ...

Even though FireBug shows errors ... all STILL LOAD files are asynchronous! But BECAUSE there are errors ... a piece of code is then never called.

So my questions are:

  • Do I need to update all JavaScript file objects that should be contained in 'define'? (... I hope not)
  • Do you see any other problem syntactically?

The chapter code is as follows:

<script type="text/javascript"> ///<summary>Configuration</summary> curl = { baseUrl: 'Includes/JavaScript/' }; </script> <script src="Loaders/Curl/curl.js" type="text/javascript"></script> <script type="text/javascript"> function onSuccess() { } function onError(ex) { //alert(ex); } require(["MooTools/Core/mootools-1.2.2-core-jm", "MooTools/mGeneral", "jQuery/Core/jquery-1.3.2", "jQuery/Core/jquery.tools.min", "jQuery/ThirdPartyPlugIns/jquery.tmpl"]) .then(onSuccess, onError); //require(["jQuery/TopUp/top_up-min"], null); require(["jQuery/ThirdPartyPlugIns/jquery.dimensions", "jQuery/ThirdPartyPlugIns/jQuery.Color.Animations", "jQuery/ThirdPartyPlugIns/jquery.corners.min", "jQuery/ThirdPartyPlugIns/jquery.tipsy", "jQuery/ThirdPartyPlugIns/jquery.numberformatter-1.1.0", "jQuery/ThirdPartyPlugIns/jquery.tipsy"]); require(["general", "WindowCenter", "ThirdPartyPlugin/KeyBoardCapture", "ThirdPartyPlugin/bsn.AutoSuggest_2.1.3", "ee/8Ball", "ee/EE"]); </script> 

Again ... I'm sure this is caused by an inexperienced with AMD-style code, but I still need help ... so anyone is appreciated.

+4
source share
2 answers

Typically, you should wrap your modules in define() or add define() at the end of the file if these modules have no dependencies. It seems that all of these modules are jQuery dependent, if not other modules / files.

Since you are not using the standard AMD require() / define() protocol, AMD does not really help you with these modules. If you do not plan to write your own modules using define() , you can use almost any asynchronous loader.

However, there is a way to get curl.js to work with non-AMD modules / files. Use js! plugin. Here is your first block of files translated into js! plugin (note I also added an ".js" ext, which I like to do non-modules on):

 // we load the core files first, then get the next block that depends on them curl([ "js!MooTools/Core/mootools-1.2.2-core-jm.js", "js!jQuery/Core/jquery-1.3.2.js" ]).next([ "js!MooTools/mGeneral.js", "js!jQuery/Core/jquery.tools.min.js", "js!jQuery/ThirdPartyPlugIns/jquery.tmpl.js" ]).then(onSuccess, onError); 

If any of these files in each array is dependent on each other, you can also use an order suffix for them to ensure that they wait for other files to execute / evaluate (make sure you set the correct cache headers). Actually, the order suffix is the fastest method if there is no problem with caching (mobile browsers add some additional restrictions on file size).

Have there been other error messages? In particular, I would expect curl.js to throw at least one error, except for only "Promise not completed".

Also, check the Network tab (Firebug) or Network tab (Chrome) to check that curl.js is in the right place for the modules.

FWIW, I plan to remove the require โ†’ curl alias. The reason is that the global require function is non-standard (and clearly not standardized in the AMD proposal). I suggest using curl() instead of require() .

curl.js also allows top-level api api to be explicitly entered through the apiName configuration parameter if you really want to use the name "require". :)

 <script>curl = { apiName: "require" }; </script> <script src="path/to/curl.js"></script> <script>require(["some/modules"]).then(success, failure);</script> 

More FWIW: the standard require usually required only in the module and can be requested by including it in the dependency:

 define(["require"], function (require) { require(["another/module"], function (another) { // use another module here }); }); 

- John

+1
source

If you are doing a normal javascript file download (not modules), I would advise you to check out LABjs ( http://labjs.com ). LABjs focuses on being the most performance-optimized loading solution (with the exception of some other features, such as module / dependency style elements).

In fact, LABjs 2.0a ( https://github.com/getify/LABjs/blob/master/next/LAB.src.js ), which will be fully released in the next few days, is really exceptionally fast (even more than 1.2) with parallel loading of common scripts. I urge you to try if only (as John will not be convinced above) you plan to pass to module syntax ... then stick to Curl or RequireJS.

0
source

All Articles