Closed dpantel closed 7 years ago
The first error looks like a domain name resolution error. The second error is thrown by LoadJS when you re-use a bundle name ("bundle" in this case).
To avoid the bundle name error you can use the loadjs.reset()
method to reset all the bundles or loadjs.done()
method to control when the bundle gets defined:
loadjs('BROKEN-URL-TO-CDN/lib.js', {
before: function(path, el) {
//add SRI and crossorigin
el.integrity = 'xxxx';
el.crossOrigin = 'anonymous';
},
success: function() {
loadjs.done('bundle');
},
error: function(pathsNotFound) {
//fallback to local copy
loadjs('js/lib.js', {success: function() {loadjs.done('bundle');}});
}
});
Works like a charm. And now I also have a better understanding of what done() does (was not very clear from the docs).
Thank you!
Great! Happy to hear it worked and thanks for the feedback!
Hello. Forgive me if I am missing something obvious. I am a JS novice...
I am trying to load a file from a CDN and fall back to a local copy on error. When testing the fallback, I purposefully corrupted the URL of the CDN, expecting loadJS to load the local file. However, what I got instead was this:
Please help me understand what is going on (and how to fix it). Thanks.