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

feat: fallback CDN #23

Open
mastilver opened this issue Jul 18, 2017 · 1 comment · May be fixed by #27
Open

feat: fallback CDN #23

mastilver opened this issue Jul 18, 2017 · 1 comment · May be fixed by #27

Comments

@mastilver
Copy link
Owner

inspired by jso0/html-webpack-cdn-plugin#1

Depends on #13


options.fallbackResolver

Type: string || function

Default: 'module-to-cdn' || 'module-to-jsdelivr'

Similar to resolver but the module will be loaded from this CDN only if the main CDN is experiencing issues


It will create a new file which will contains for each module:

window.React || document.write('<script src="https://unpkg.com/[email protected]/dist/react.js"><\/script>');

NOTE: resolver and fallback must both return a valid cdnConfig otherwise the module is ignored

@mastilver mastilver changed the title fallback feat: fallback CDN Jul 18, 2017
@mastilver
Copy link
Owner Author

This would be a better way as it would virtually handles all types of resources, not only JavaScript:

var fallbackUrls = {
  'https://unpkg.com/[email protected]/dist/react.js': 'https://cdn.jsdelivr.net/npm/[email protected]/dist/react.min.js'
};

window.addEventListener('error', function(e) {
    var failedUrl = e.target.src || e.target.href

    if (failedUrl in fallbackUrls) {
        if (isJs) {
            document.write('<script src="https://unpkg.com/[email protected]/dist/react.js"><\/script>');
        } else { ... }
    }
}, true);

@mastilver mastilver linked a pull request Aug 1, 2017 that will close this issue
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 a pull request may close this issue.

1 participant