Certain modules require config variables to work. For code that is loaded conditionally, the config is always loaded unconditionally. As a result of this problem, many config variables for MobileFrontend that are designed for ResourceLoader modules that can be run in the desktop or mobile context can be loaded in the desktop startup module.
Example
Consider the ResourceLoader module:
'foo' => [ 'scripts' => [ 'foo.js' ] ],
and the file foo.js:
alert( mw.config.get( 'wgFoo' );
The config value for wgFoo is often defined in one of many places - it could be in the skin's HTML or it could be in the startup module.
Usually, we may use of the hook onResourceLoaderGetConfigVars
However, there is a problem with this approach...
If the module 'foo' is never loaded on the page, wgFoo is loaded anywhere.
Possible solutions
Inside skin/extension.json
Ideally, we'd define a set of key value in the module itself
e.g.
'foo' => [ 'scripts' => [ 'foo.js' ], 'config' => [ 'random-int': 200, 'wgFoo' ], ],
The benefits of this, is that the names of the config are predictable. However, one downside of this approach is I cannot easily pass variables that depend on context or PHP consstants.
e.g. in MobileFrontend we have:
'wgMFThumbnailSizes' => [ 'tiny' => MobilePage::TINY_IMAGE_WIDTH, 'small' => MobilePage::SMALL_IMAGE_WIDTH, ],
Inside hook
A hook could be added to all ResourceLoaderFileModules
$vars = []; Hooks::run( 'ResourceLoaderGetModuleConfigVars', [ &$vars, $moduleName, $skin ] );
This would allow us to define anything within config, and scope it only to the modules that needs it.
if ( $moduleName === 'foo' ) { $vars['wgFoo'] = self:VALUE . 'px'; }