cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

Incompatible with jquery file upload plugin #204

Closed rotatingJazz closed 10 years ago

rotatingJazz commented 10 years ago

http://blueimp.github.io/jQuery-File-Upload

Code fails to execute, no matter what (jquery is loaded before with !order) - had to force each plugin's file to not register as AMD to make it work (oh, thou lovely false :)).

(function (factory) {
    if (typeof define === "function" && define.amd && false) {
        // Register as an anonymous AMD module:
        define(["jquery"], factory);
    } else {
        // Browser globals:
        factory(jQuery);
    }
}(function( $, undefined ) {
...
unscriptable commented 10 years ago

Hey @rotatingJazz,

I just peeked at the modules at https://github.com/blueimp/jQuery-File-Upload/tree/master/js. While I didn't see any that looked exactly like the code snippet you pasted, it does appear that they are all AMD-aware. This means that you should not use the js! plugin to load them.

Did you try loading the file upload plugin as just an AMD module?

-- John

rotatingJazz commented 10 years ago

@unscriptable

Thank you for looking into it. It 's this one: https://github.com/blueimp/jQuery-File-Upload/blob/master/js/vendor/jquery.ui.widget.js

I 've had the same issue with another plugin as well (jquery datatables) and again I had to force it not to load amd style. Using the js! plugin or not to load it made no difference.

My guess is that since I 'm using the js! plugin to load jquery, it doesn't register as amd but typeof define === "function" && define.amd is true anyway and so the execution path gets to the define() line. At that point, the requirement is not satisfied and it fails to load silently.

Why am I using the js! plugin to load jquery then? - for one, //code.jquery.com/jquery-latest.min.js produces an error: Uncaught Error: define() missing or duplicated: //code.jquery.com/jquery-latest.min.js. And since it was not clear to me from the documentation if loading jquery as an AMD module would guarantee that it would execute always before the rest files that where loaded with the js!/!order plugin, I thought I 'd play it safe and load everything via the js! plugin.

unscriptable commented 10 years ago

Uncaught Error: define() missing or duplicated is a sign that you have not mapped a path to jquery. The jquery folks unfortunately decided that jquery should be a "named module" rather than an anonymous one. This forces you, the developer, to map a path to jquery. Try this (or any other variation to configure curl):

curl.config({
    paths: {
        jquery: '//code.jquery.com/jquery-latest.min.js'
    },
    preloads: ['jquery']
});

The preloads option ensures that jquery is loaded before you attempt to load any non-AMD jquery plugins with the js! curl plugin.

-- John

unscriptable commented 10 years ago

Hey @rotatingJazz, I am closing this issue for now. If you are still experiencing issues, please reopen it and provide some details. Thanks! -- John

rotatingJazz commented 10 years ago

@unscriptable Thank you very much for your response, it made things clear to me! :) (and for the @ mention - for some reason github didn't send me a notification for your previous response and I 'd have missed it).