0

I am working on a live site hosted on webflow. I have two javascript files

  1. http://localhost:3000/dev.js
  2. https://cdn.jsdelivr.net/live.js

I want to link them in a way if dev.js is not loaded, it will load live.js

I am using the following script, but it keeps pinging dev.js and showing errors in the console. Is there a better way to achieve this?

<script>
console.log('yes');
$.getScript( "http://localhost:3000/dev.js" )
  .done(function( script, textStatus ) {
    //do nothing
  })
  .fail(function( jqxhr, settings, exception ) {
    //load alternative script
    $.getScript( "https://cdn.jsdelivr.net/live.js" )
      .done(function( script, textStatus ) {
        //do nothing
      })
      .fail(function( jqxhr, settings, exception ) {
        console.log( 'Error online script loading' );
    });
});
</script> 
Imran
  • 1,094
  • 1
  • 21
  • 41

0 Answers0