This is similar to How to tell if a <script> tag failed to load. But my question is specifically about plain old <script>
tags in my HTML body like so
<script type="text/javascript" src="/path/to/my/script.js"></script>
I have a custom window.onerror
function that I wrote to deal with general script errors. And indeed, if such a script has a syntax error or some other runtime error occurs while evaluating the script itself, that is handled correctly by my onerror
function.
But if the script fails to load at all, because of an interrupted connection or even a 404 or other server error, window.onerror
is not called. How can I detect this kind of failure programmatically in Javascript?
To clarify: I realize I could just put an onerror
attribute in every single script tag. I'm asking if there's a better way, something comparable to my global window.onerror
or some way of making that function be called.
script
tag in my HTML.onerror
attribute to my script tag. Is that really the only way?script
tag that was already inserted in the template and ascript
tag that was inserted later using JS? I don't see what is so special about your question in contrast to the one you've linked to.