Asset ordering was previously determined by three things:
1. The order that libraries are attached during the request
2. The dependencies of libraries between each other
3. The weight definition of individual files in library definitions, if one is specified
This caused multiple issues with low cache hit rates for asset aggregates (because identical combinations of libraries can be sent in different orders) and in some cases invalid aggregate requests (because library ordering was not 100% determinate).
The ordering algorithm has now been modified so that only library dependencies and asset weights are taken into account.
In some cases, this may require changes to contributed or custom library definitions:
1. If a library specifies a weight so that its file is loaded before its dependencies, that weight definition could be ignored in some circumstances, it will now be respected. If the file actually depends on JavaScript APIs from files loaded later, this can result in JavaScript errors. The solution is usually to remove the weight.
2. If a library has an undeclared dependency on another library, whether explicit use of its JavaScript API or implicit such as relying on markup, that may have previously worked 'by accident' due to the order of attachments during a request, but might not now. In these cases, just adding a dependency to the library definition should be sufficient.
Note that core's vertical-tabs.js file was declaring an invalid weight (putting it before its dependencies) and this has been removed. If custom or contrib JavaScript is implicitly depending on vertical-tabs.js being loaded very early, this might result in regressions, but once again adding a dependency on the vertical tabs library should be sufficient.
In general, libraries should avoid setting custom weights where possible, and rely on properly declaring dependencies between libraries instead wherever possible.
Recommendation to investigate hidden dependency issues: Export the unaggregated list of <script> tags before/after the 10.4/11.1 update. compare the list of included files, to see what changed and review if the problematic snippet is now loaded before one of those that are now loaded after it. git word diff is useful to compare the list since query strings changed.
Example: Entity Browser did not correctly depend on views ajax library: #3485010: Update CI configuration and fix JS dependencies
If libraries are added per page, per view, per template etc. rather than to all pages, then these need to be taken into account also, because not all JS files may be loaded on every page - so comparing the order of
tags on the front page only may not be sufficient.