The bottom scripts "site" and "user" currently use a very ugly synchronous script tag inside document.write.
Backstory: (Note that not all arguments are still relevant today, this is just for context.)
- They're not loaded with mw.loader.load() because these are legacy scripts that needs execution in global scope (or T65728: ResourceLoader: User scripts should not execute in global scope).
- We generally avoid ajax because of cross-domain in old browsers (though not a concern anymore for WMF since the demise of bits.wikimedia.org), because using XHR means we have to use eval, which means we lose useful stack traces.
- They're not a plain <script> tag because the request has to be conditional on window.mw - e.g. conditional on the browser being supported by MediaWiki and jQuery, and the startup request having succeeded without network or runtime problems.
- They're not a plain <script> and don't use <script async> because it needs a callback to update the mw.loader state machine and allow dependant modules to resolve.
- Unlike regular modules, we can't append a "state()" call to the server response because it's an unwrapped legacy script that may return early or throw exceptions, rendering the "state" call unreachable and causing the loader to hang indefinitely.
But.. what we can do is simply use mw.loader's addScript() which we already use for normal module requests. It creates a script tag in JavaScript (which are always asynchronous) and has a callback.