-1

I am wondering, is it possible to provide an alternative path for a file if it cannot be found from the original one? For example I provide an src which points to an external source, this should be the default src, but if it cannot be reached for some reason, then it should load the file from the source folder.

Example:

Original:

<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>

And if this cannot be loaded, then:

<script src="js/swagger-ui-bundle.js"></script>

So I could load the newest from the js file, or the default I have.

Thanks!

Mr. Polywhirl
  • 31,606
  • 11
  • 65
  • 114
victorio
  • 5,234
  • 16
  • 65
  • 96
  • 1
    I think you just list them in precedence with the fallback links after the primary ones. There is a [tutorial here](https://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx) that explains how to do this in RequireJS. Pay attention to the very end of the post. – Mr. Polywhirl Jan 07 '20 at 13:40
  • 1
    I think you can find someting [here](https://stackoverflow.com/questions/14644558/call-javascript-function-after-script-is-loaded) with `script.readyState` – Simon Jan 07 '20 at 13:44

1 Answers1

1

Try just putting them in order in your script like so:

<script src="js/swagger-ui-bundle.js"></script>
<script src="https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"></script>

so that it loads one and then tries to load the other. This should work unless you have conflicting scripts.

figbar
  • 454
  • 4
  • 16