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

Add fallback URL functionality #97

Closed
wants to merge 3 commits into from
Closed

Add fallback URL functionality #97

wants to merge 3 commits into from

Conversation

markrendle
Copy link

This change allows an array of URLs to be passed for a script, where if the first URL fails the loader will try the next, and so on, similar to the Require.js feature. I noticed that on the Basket.js homepage it says that only same-origin URIs are supported, but the XHR approach will work fine with modern browsers and most CDNs allow an Access-Control-Allow-Origin wildcard, so I think this adds value.

@addyosmani
Copy link
Owner

Thanks for the PR. I understand how the implementation works, but could use a little convincing of the use-case :) If you're working on an app where you have control of the locally served files, wouldn't there be a low chance of a script not being available? Any extra details would be useful :)

@markrendle
Copy link
Author

I like to take advantage of public CDNs where possible, to improve loading times and reduce load on my servers; for example, I use googleapis for AngularJS and cdnjs for jQuery. I also serve the application JS files through MaxCDN. But I also have copies of those libraries on my site with fallback code if the CDN is unavailable.

I want to use Basket.js as an additional optimization, but I'd still like to use the CDNs for the initial download of those files, and have the fallback functionality. And the cross-site thing isn't an issue in my case because my application requires a CORS-compatible browser anyway.

@@ -44,6 +44,9 @@
};

var getUrl = function( url ) {
if (url instanceof Array) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.isArray()

@sindresorhus
Copy link
Contributor

👍 while i don't see the use myself, i know a lot of people that uses CDN with local fallback.

@markrendle can you add some docs?

@sindresorhus
Copy link
Contributor

@markrendle ping :)

@markrendle
Copy link
Author

Sorry, missed this. Will add some docs.

@sindresorhus
Copy link
Contributor

ping :)

1 similar comment
@sindresorhus
Copy link
Contributor

ping :)

@sindresorhus
Copy link
Contributor

Closing for lack of response.

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

Successfully merging this pull request may close these issues.

None yet

3 participants