This is with reference to the question : How may I reference the script tag that loaded the currently-executing script?
And the most upvoted answer. It mentions in option 6 : "6. Get the last executed script"
Problems
Does not work with asynchronous scripts (defer & async)
Does not work with scripts inserted dynamically
My script is not async, but the page might have other scripts that are async or defer. Would this option work in that case as well? I have not been able to find an answer to this anywhere.
If I understand you problem, I think closures would help solve this.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
You may also want to organize your JS files so that your async files are included in an async.js file and non-acyned files in non_async.js and so on.
I hope this is clear.
Cheers,
Tim