Replies: 1 comment
-
I haven't found an ideal solution to this but have gone with a script at the end of the body like the one below which adds an onerror attribute retrospectively. My vite scripts are loaded async. Without an async attribute on earlier scripts in the dom this almost certainly won't work. function handleScriptLoadErrors() {
console.error("script load error");
}
const scripts = document.getElementsByTagName("script");
for (let i=0; i<scripts.length; i++) {
let script = scripts[i];
if (script.src && script.async) {
script.setAttribute('onerror', 'handleScriptLoadErrors();');
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a react app and a function named 'handleScriptLoadErrors' in index.html file in the head tag.
function handleScriptLoadErrors() { console.error("script load error"); }
my index.html file content:
I want, when I build my app with Vite, for it to place 'onerror' in the script file load (onerror="handleScriptLoadErrors()"). The expected output after build:
how can i do this?
Beta Was this translation helpful? Give feedback.
All reactions