'How to check HTTP Status Code of dynamically added *.js

for a project I need to check the Response Code of a dynamically added JS into DOM. So Code looks basically like this one:

var newScript = document.createElement("script");
newScript.src = "http://www.example.com/dynamic-XXX.js";
target.appendChild(newScript);

The XXX will change and I am loading the File from Google Cloud Storage. So if I have a 200, everything is fine. But I need to check if I have 201 Status Code.

Any Ideas how to solve this in a nice way ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source