There are similar questions to this but not this exact one. The others are more concerned with seeing the contents of the script.
I make a request for a JavaScript script using a regular script tag. The server decides whether it wants to (a) return the script directly, (b) return the script via a 302, or (c) return no script at all using a http 204 "no content".
I simply want to know if a script was successfully loaded or if I got no content. Doing this doesn't work on an external script (like it does work on inline scripts):
var length = document.getElementById("somescript").innerHTML.length;
As many of you will know, the innerHTML of an external script is reported as an empty string regardless of whether it's cross-domain.
I've looked into the properties of the element and can't see any property that tells me either the length, or the status of the script. If the script being loaded was under my control I could simply look for the presence of some global variables or functions, but it's not.
This question is not a duplicate. I'm not using jQuery and looking for globals created doesn't work as the script is unknown to me (I receive the URL to it dynamically, it could be any script).
I'm currently testing using Charles rewrite tool. Whether I specify to leave the request alone or rewrite the response to be empty with a http 204 status, I can't tell the difference from a script point of view. The src is still the same regardless of whether the script returned fully or if no script was returned.
I think my only options are to keep a check on the DOM and look for new elements being added to it (which couldn't happen if I got an empty script back) or use an Ajax request to the script, but that could potentially result in a double-hit on the server. Cache usage isn't guaranteed.