Feature summary (what you would like to be able to do and where):
It should be possible to import scripts using ImportJS files. The sitewide ImportJS file (located at MediaWiki:ImportJS) would only permit loading scripts either on-wiki or from certain wikis within the wiki farm (on Wikimedia, this can be English Wikipedia, Wikimedia Commons, Meta-Wiki, and a few other projects with highly watched MediaWiki pages). The ImportJS page would only be editable by interface administrators. Including a local script on an ImportJS page would record the usage as a transclusion. For MediaWiki space, we can couple that with T71445 to ensure that only scripts which other interface administrators have reviewed can be run.
ImportJS-[skin] files would load scripts only for a particular skin.
Likewise, for users, ImportJS and ImportJS-[skin] would import the skin for their user profile and skin respectively. The user ImportJS would permit loading scripts only from MediaWiki: and User: namespaces, as well as on specific wikis in the wiki farm.
Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
The CSS/JS incident was caused by an unvetted script being added to a user common.js file which then spread to a sitewide common.js file. This would make it harder since off site scripts cannot be loaded
Benefits (why should this be implemented?):
The two benefits are added security and improved responsiveness, since the scripts can be loaded by load.php, and it could also make it possible to use import statements at the top of scripts also recording transclusions (see T373725).