On 12 Mar 2015, at 14:24, Jason Ji jason.y.ji@gmail.com wrote:
Thanks for the responses, Brad. Is there some documentation somewhere for which modules are loaded by default and which ones aren't (e.g. mediawiki.api)?
Nothing is loaded by default.
If you make use of interfaces provided by a module, you must add a dependency on that module.
Just like your code, there is also other code on the same page (either from core or other extensions). Under race conditions (=unreliable), naturally something has to be the first module to run. Since "mediawiki.api" is quite popular, there is a good chance something somewhere might have declared a dependency on it – thus instructing ResourceLoader to load it from the server.
Other times, when your code might be the first to run, it won't be there (yet).
Even modules like "mediawiki.user" which are loaded from (almost!) every page, it still can't be guaranteed because:
1) It loads asynchronously, so while it might be requested on every page, it might be finished downloading in time before your code.
2) What wiki pages do and do not need is subject to change, just like your code might change over time to make use of different modules.
So, always always always declare your dependencies. Don't worry about other modules providing it already or about slowing things down. ResourceLoader takes care of combining requests in batches (and if more than one, in parallel). It also keeps track of modules that are already underway. Declare what you need, and it will take care of the rest.
https://www.mediawiki.org/wiki/ResourceLoader/Features
-- Krinkle