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

[rfc] Fallback mechanism #228

Open rotatingJazz opened 10 years ago

rotatingJazz commented 10 years ago

What

If any file fails to properly load (see later on), load it from a different server.

Use case

I upload static files to github to increase load speed but sometimes github is down for a little while. That breaks user experience, because the page fails to load properly.

Edit: I just had an incident with Cloudflare 's cdnjs while trying to load the flot library, so it 's not just limited to the github case.

Proposal

Instead of passing a string for each file, let 's pass an array

[ filePath, matchString, fallbackPath ]

Curl would try loading the file found on filepath as usually, then assert it ends (without taking into account any whitespace) with the matchString, and if it fails, try doing the same but this time using the fallbackPath.

Pros I see:

unscriptable commented 10 years ago

Hey @rotatingJazz,

curl.js does something like this now, but only for a single module specified as the main property of the config. If you specify a comma-separated list of ids, it will split the ids, use the first one as the primary id, and use the second item as the fallback. It sounds like that isn't sufficient for your needs, though.

The current solution is problematic since it can't tell the difference between 404s and syntax errors in a successfully loaded script. The matchString idea is interesting, but it won't work because we can't access the text of a cross-origin script.

If you have any other ideas, please share.

Thanks!

-- John