Thread:Talk:ResourceLoader/Migration guide for extension developers/Mixed purpose modules

Following [//www.mediawiki.org/w/index.php?title=ResourceLoader%2FMigration_guide_for_extension_developers&diff=482114&oldid=474774 this edit], a little info here.

ResourceLoader always loads a module's styles before executing any scripts. It is by no means "desirable for the stylesheet to be loaded before rest of html [by using OutputPage::addModuleStyles]". OutputPage::addModuleStyles will insert a hardcoded tag in your HTML that is ineffeciëntly cached and separate from the whole advanced cache-busting and cache-preserving system around ResourceLoader. Usage of direct and  tags in the output should be extremely rare and is imho to be considered deprecated (except for some core stylesheets and the ResourceLoader startup module itself).

The only scenario in which might consider loading the styles of the module from the (separate from the rest of the module) is when your module is serving two purposes, which you shouldn't be doing.

If you've got a module that has a stylesheet that is styling content outputted by PHP and/or moving around elements outputted by PHP, and at the same time have code in this module that is doing dynamic stuff after the document is ready (e.g. something that isn't visible or needed before the page is loaded), then one should split the module.

One module for initialization stuff. This module should have the  property in the module registry set to "top". This will tell the client to load the module from the before parsing the body contents. So that whatever is in here will be in memory before the page is displayed. The other module would contain everything else and can simply be loaded regularly from the asynchronous queue that arrives at or a little after the document is ready.

Both should be added to the load queue in OutputPage::addModules. That way the module properties and the load queue are kept separate, the client will use the module registry properties when it loads it and do the right thing (instead of telling OutputPage to force loading it in a certain way, simply let the client handle it).