Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rfc] Fallback mechanism #228

Open
rotatingJazz opened this issue Sep 9, 2013 · 1 comment
Open

[rfc] Fallback mechanism #228

rotatingJazz opened this issue Sep 9, 2013 · 1 comment

Comments

@rotatingJazz
Copy link

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:

  • We bypass the "404 not reported properly" IE issue
  • We make sure we load js code and not some "Oops, not found" page
  • By matching at the end and not accounting for whitespace, we don't have to worry for any transparent minifications some CDNs (or deployment tools) do (e.g. a file starts with a comment and it gets removed). Matching with something like ); at the end would probably do the trick consistently.
  • No practical speed penalty considerations
@unscriptable
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants