How can I go about setting up a fallback script, using jQuery or any other method? Why does this method not work?
https://api.jquery.com/jQuery.getScript/#jQuery-getScript
I use the code below to set a fallback script in case I get a 404 or similar on my primary script.
$.getScript( "https://cdnjs.cloudflare.com/ajax/libs/three.js/r123/three.min.js" )
.fail(function( jqxhr, settings, exception ) {
$.getScript( "https://cdn.jsdelivr.net/npm/three@0.123.0/build/three.min.js" )
})
When I add some random characters to the first URL to simulate a situation where the script is unavailable, I expect my code to load the script from the second URL and continue execution, but I get this error instead
GET https://cdnjs.cloudflare.com/ajax/libs/three.js/r123/threes.min.js?_=1608231826270 net::ERR_ABORTED 404
And my code is halted.
This shouldn't be happening since all my code is in the .done() callback of the first $.getScript call.