How to introduce CDN into callback

the recently used cdn is always wrong. First, the bootcss is hung up directly. After switching to unpkg, it is found that you need to hang up vpn at some time before you can access it. Can you introduce two sets of cdn, one of which fails and then the other?
originally intended to use the onerror methods of link and script, but found that the onerror method of link inserted in js does not seem to execute.

const cssCdns = [
    {
      key: "element",
      // link1: "https://unpkg.com/element-ui/lib/theme-chalk/index.css",
      link1: "https://ttt",
      link2: "https://cdn.staticfile.org/element-ui/2.4.7/theme-chalk/index.css"
    },
    {
      key: "iview",
      link1: "https://unpkg.com/iview/dist/styles/iview.css",
      link2: "https://cdn.staticfile.org/iview/3.0.1/styles/iview.css",
    },
    {
      key: "highlight",
      link1: "https://unpkg.com/highlight.js/styles/solarized-light.css",
      link2: "https://cdn.staticfile.org/highlight.js/9.12.0/styles/solarized-light.min.css",
    },
  ],
  jsCdns = [
    {
      link1: "https://unpkg.com/vue/dist/vue.min.js",
      link2: "https://cdn.staticfile.org/vue/2.5.17/vue.min.js"
    },
    {
      link1: "https://unpkg.com/vue-router@3.0.1/dist/vue-router.min.js",
      link2: "https://cdn.staticfile.org/vue-router/3.0.1/vue-router.min.js"
    },
    {
      link1: "https://unpkg.com/vuex@2.2.1/dist/vuex.min.js",
      link2: "https://cdn.staticfile.org/vuex/3.0.1/vuex.min.js"
    },
    {
      link1: "https://unpkg.com/iview/dist/iview.min.js",
      link2: "https://cdn.staticfile.org/iview/3.0.1/iview.min.js"
    },
    {
      link1: "https://unpkg.com/element-ui/lib/index.js",
      link2: "https://cdn.staticfile.org/element-ui/2.4.7/index.js"
    },
    {
      link1: "https://unpkg.com/highlight.js@9.12.0/lib/highlight.js",
      link2: "https://cdn.staticfile.org/highlight.js/9.12.0/highlight.min.js"
    },
  ]
  let css=document.createElement("link");
  cssCdns.forEach(item => {
    css.setAttribute("rel", "stylesheet");
    css.setAttribute("type", "text/css");
    css.setAttribute("href", item.link1);
    css.setAttribute("key", item.key);
    // css.setAttribute("onload","cssLoadOK(""+url+"")");
    css.setAttribute("onerror", "cssLoadError()");
    document.head.appendChild(css);
  })
  function cssLoadError () {
    debugger;
    console.log("error");
  }

however, if you introduce the link tag directly into head, the onerror method will execute =. =
link directly introduces failed status to display failed, but looping insert failure status in js is canceled. If you insert one directly into js instead of forEach, it is also failed. That should be the problem. But how to solve it is still being explored. =

Jul.30,2021

put let css = document.createElement ('link'); into forEach.
this can solve the css problem, but js's cdn onerror doesn't seem to be able to use this method =. = because I used it in vue-cli, although the onerror method was executed, there was no guarantee that the new cdn was loaded before the interface was loaded. So the js code will report an error. I'll look for = again. =

Update:

<script>window.Vue || document.write('<script src="./static/js/vue.js"><\/script>')</script>
Menu