Much has been written about how to parameterize SCRIPTs. There is a nice overview of approaches on SO. That post and everything else I've found on the topic of script parameterization make one of the following two assumptions:
The SCRIPT element is hardcoded on the page and, therefore, it is the last SCRIPT element on the page when its code runs, making it easy to discover. Then it's a simple matter of reading data attributes, etc.
The SCRIPT element is uniquely identifiable in some way, e.g.,
id
orsrc
filename, etc.
What's an approach to parameterizing SCRIPTS when neither of the above assumptions are true and, further, there is no possibility for server-side customization and we want the script to be cached?
As an example, consider an async scenario where in the top window of a page JavaScript may add any number of SCRIPT elements with the same src
URL anywhere in the content at any point of time while other unrelated changes to the DOM are happening. Each script must receive one string parameter. Each string parameter value is unique within the context of the page.