Page MenuHomePhabricator

Only register gadgets client-side from startup if relevant for the current skin
Closed, ResolvedPublic

Description

Since the startup payload varies by skin, the Gadgets extension should take advantage of this by not registering gadgets that are only enabled in certain skins.

Event Timeline

@Krinkle I found documentation for how to add additional scripts for specific skins, but how can $wgResourceModules be set to only load entire modules for specific skins?

This task is not about how modules are loaded (addModules), and not about how module content is defined (scripts/packagFiles etc).

The task is about when modules are registered. Registration reduction helps improve the startup module performance.

Registration can happen in one of two ways:

  • Statically, from extension.json (or Resources.php) with an array or object for simple file modules.
  • Dynamically, from the ResourceLoaderRegisterModules hook.

Gadgets are registered dynamically, since they are defined by end-users via MediaWiki:Gadgets-definition from a page.

There is a Gadget option called skins that gadget developers can use to indicate when the gadget module should load. The PHP code in the Gadgets extension uses this today to only call addModules in skins that the gadget supports.

The proposal is that for gadgets that use the skins option, to also only register them in skins that the gadget supports.

Krinkle triaged this task as Medium priority.Jul 3 2020, 4:14 PM
Krinkle added a project: patch-welcome.

Change 735980 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/Gadgets@master] Only register gadgets if relevant for the current skin

https://gerrit.wikimedia.org/r/735980

Change 735980 abandoned by SD0001:

[mediawiki/extensions/Gadgets@master] Only register gadgets if relevant for the current skin

Reason:

Wrong approach

https://gerrit.wikimedia.org/r/735980

Change 749861 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/core@master] resourceloader: Only register modules client-side if relevant to current skin

https://gerrit.wikimedia.org/r/749861

Change 749862 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/Gadgets@master] Add getSkins() in GadgetResourceLoaderModule

https://gerrit.wikimedia.org/r/749862

Change 749861 merged by jenkins-bot:

[mediawiki/core@master] resourceloader: Add Module::getSkins to skip irrelevant modules from startup

https://gerrit.wikimedia.org/r/749861

Change 749862 merged by jenkins-bot:

[mediawiki/extensions/Gadgets@master] Add getSkins() in GadgetResourceLoaderModule

https://gerrit.wikimedia.org/r/749862