Gadgets, when enabled by a user, load on all pages in all namespaces. This doesn't cause any immediate functional problems, but is inefficient. In some cases, very unacceptably inefficient, to the point that a gadget may be removed from a wiki or disabled due to performance problems. This is usually worked around in one of two ways:
- The gadget is split into two parts. A part that contains the actual gadget itself (hidden, disabled by default). And a (tiny) second part that is loaded always and checks whether the current page is the "right" one, and then loads the other.
- Downside: Two definitions instead of one.
- Downside: The page will first load without the gadget, and then later the gadget gets loaded (typically between 1-10s seconds later, depending on the connection and bandwidth).
- The gadget is made hidden and is instead loaded by url parameter (e.g. /wiki/Example?withModule=ext.gadget.foo).
- Downside: Cannot be enabled on a per-user base (url parameter applies to all users). It also means the gadget only loads when the user follows a specific link, e.g. not when visiting the page through other means.
- Downside: The page will first load without the gadget, and then later the gadget
We should instead add an option directly in the Gadgets extension to specify when a gadget should load (by default still everywhere).
Eg. based on the namespace, or page title, or page action, or canonical special page name.
We should add an option to specify what pages a gadget is active on. Many probably just do this manually, but it looks reasonable as some gadgets would only be useful for contributors' talk pages for example. This could be a namespace name, or sometimes even a glob mask (Wikipedia talk:Articles for Creation/*).
- T8883: Allow page-specific inclusion of <script>s, etc. in header
- T31028: Provide more flexibility for defining if a gadget should be visible on [[Special:Preferences]]
- T241524: Parser function for loading gadgets
- T204201: Extend MediaWiki:Gadgets-definition capabilities