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

errorback function never called on 404 #197

Closed stevenvachon closed 11 years ago

stevenvachon commented 11 years ago

I combined curl with the plugins: css, j, text

curl(
    [
        "js!scripts/library.js",
        "css!stylesheets/style.css",
        "text!templates/template.html",
        "js!scripts/library123.js"  // renamed to cause a 404
    ]
).then(
    function(){ console.log(arguments); },
    function(){ console.log("ERROR"); } // never called
);

Here is the browser (Safari) error in the console: Failed to load resource file://localhost/Users/user/Desktop/Test/scripts/library123.js

unscriptable commented 11 years ago

Hey @stevenvachon,

This is a known problem in IE (all versions). I'm surprised to see this in Safari. Have you checked other browsers, too?

Fwiw, there's a way to ensure failure detection in IE (and other browsers): use the !exports option. If you know a global variable that is declared in the legacy js file, you can check for it:

curl(
    [
        // for instance, file declares `someGlobal.property`
        "js!scripts/library.js!exports=someGlobal.property", 
        "css!stylesheets/style.css",
        "text!templates/template.html",
        // for instance, file declares `anotherGlobalThingy`
        "js!scripts/library123.js!exports=anotherGlobalThingy"
    ]
).then(
    function(){ console.log(arguments); },
    function(){ console.log("ERROR"); } // never called
);

More info: https://github.com/cujojs/curl/wiki/js#exports-option

Maybe use this as a work-around while we investigate?

-- John

scothis commented 11 years ago

This may also be an issue with the file:// scheme instead of http://, have you tested using an http server?

stevenvachon commented 11 years ago

Running it on http fixed it. Kind of a pain as I like to work local, but works. Is it possible to fix this?

unscriptable commented 11 years ago

Hey @stevenvachon,

It's up to the browser vendors. They place lots of restrictions on XHR and script injection, including access to the file: protocol. Afaik, there's not anything we can do about it. :(

Each browser handles the situation in different ways. Some block all file: script injections, some just fail to provide proper feedback. I guess that's why I didn't recognize the problem immediately.

This sounds like a documentation problem. I'll add some more obvious info about this and then close the issue.

Regards,

-- John

unscriptable commented 11 years ago

I added some notes to the README.

scothis commented 11 years ago

@stevenvachon There are many simple HTTP servers arround, but I use serv. npm install -g serv. By default serv will start an HTTP server in the current working directory and expose those files to localhost.

https://github.com/scothis/serv

unscriptable commented 11 years ago

Thanks Scott. I forgot to mention that! We also include serv in cujojs/seed. That makes it super easy to create a cujojs app. npm install && npm start Done!

stevenvachon commented 11 years ago

Thanks guys!