Find script tag that have failed to load when document's readyState is complete
npm install failed-to-loadAdd this attribute "onload" with "this.loaded=1" in its value (onload="this.loaded=1")
``html`
Register check for window load
`js`
import { register } from 'failed-to-load';
register();
This will throw an ayncronous error to be caught by your global onerror callback.
> `jsFailed to load necessary script tags upon window load
> Error{
> message:
> my-script-922a511f02d148e4c9390526d85ca519.js
> other-script-693e810ff27604e6da274da4c77e136c.js,`
> code: 'ERROR_NECESSARY_SCRIPT_NOT_LOADED',
> files: [
> [object HTMLScriptElement],
> [object HTMLScriptElement]
> ]
> }
>
Alternatively, you can register a callback to catch the error (then it will not be thrown)
`js`
register(
error => logger.warn(error)
);
Check and report manually:
`js
import { check } from 'failed-to-load';
window.addEventListener('load', () => {
const missing = check();
if (missing.length) {
logger.warn({
message: 'script files not loaded on page load',
files: missing.map(({ src }) => src)
})
}
});
``