Is there a way to know if a link/script is still pending or has it failed

后端 未结 2 982
粉色の甜心
粉色の甜心 2020-12-01 13:29

I\'d like to know from the html below, if link[rel=import], link[rel=stylesheet], img and script are pending/load

2条回答
  •  感情败类
    2020-12-01 13:55

    You can utilize onload, onerror events of element; see Browser CSS/JS loading capabilities at right column.

    Create an object to store status of all requests and resolved or rejected Promise corresponding to the element.

    Reject Promise at onerror event; use .catch() chained to Promise.reject() to handle error so that Promise.all() will not stop processing resolved promises within array passed as parameter. You can also throw error from .catch() at onerror handler to Promise.all() if any rejected Promise should stop processing of resolved promise within array of promises.

    At window.onload event handler, use Promise.all() to process all resolved links, using same function called before window.onload event. To wait for results of Promise.all() to be available, set src of last

    App logo

    plnkr http://plnkr.co/edit/DQj9yTDcoQJj3h7rGp95?p=preview

提交回复
热议问题