How to detect when one or more JS/CSS library fail to load (e.g. CDN)?

前端 未结 3 1770
天涯浪人
天涯浪人 2021-01-07 11:01

Premise: I\'ve found these two answers but I don\'t understand how I can sistematically apply it for many libraries:

Detect and log when external Ja

3条回答
  •  我在风中等你
    2021-01-07 11:32

    Just add an onerror handler to the tag. This can call a fallback, give the user a message etc.

    Example

    Using a non-existing url will here pop up an alert:

    For custom function, just define a script block in the header before the link tags so you can call a custom function:

    
    
    

提交回复
热议问题