I have a function which at some time does document.getElementsByTagName("script")
and it wants to know for each script if it was loaded already.
I'd like to get a Promise which is fulfilled if it was loaded and pending if it's still going on, so I can attach next steps with .then(...)
and be sure they get executed.
I could attach a load event I suppose, but if the script was already loaded, I wouldn't ever get the event.
I could work around this by making some assumptions, namely that I am in control of all dynamic script tags, and for static script tags, the document.currentScript is always the last script loaded so far and all preceding scripts are done loading, assuming they were all static. But those assumptions might not always be true.
So, is there a way to check the status and generate Promise that depending on the status will either start as fulfilled (resolved) or be fulfilled by the load event firing?