Reduce amount of code loaded in MwEmbedSupport and TimedMediaHandler startup and BeforePageDisplay
Closed, ResolvedPublic

Description

Whenever possible, modules should be loaded on demand (e.g. specific pages, or in response to a user action), not in startup. If startup modules are needed, they should be as svelte as possible.

MwEmbedSupport.hooks.php adds five, some of which have their own dependencies: https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FMwEmbedSupport.git/45a59b6ee3b9de6dc764cbd3fd6c9d7b3139718b/MwEmbedSupport.hooks.php#L28


Version: master
Severity: normal
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=47145

bzimport set Reference to bz55550.
bzimport added a subscriber: Unknown Object (MLST).

The same goes for BeforePageDisplay in TimedMediaHandler. BTW, I'm fine with splitting this bug, but there is no component for MwEmbedSupport yet.

Change 88943 had a related patch set uploaded by Mattflaschen:
Remove dialogFitWindow and jquery.ui.dialog from mwEmbedUtil

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

Change 88944 had a related patch set uploaded by Mattflaschen:
Correct mw.PopUpMediaTransform dependency

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

On my local wiki, those are enough to stop it from loading jquery.ui.dialog (and all of its dependencies, e.g. jquery.ui.core) on unrelated pages (e.g. the Main Page).

Thanks to Ori for his new mw.loader.inspect method which led me into checking this out.

https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FTimedMediaHandler.git/af412751c8bea1012f9715c16d49ffa5ca29f7aa/TimedMediaHandler.hooks.php#L350 is also double-loading the mw.PopUpMediaTransform CSS.

I'm pretty sure the CSS is useless without the JavaScript. If so, I think the addModuleStyles can be removed.

Change 88944 merged by Mdale:
Correct mw.PopUpMediaTransform dependency

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

Spage added a comment.Oct 26 2013, 7:02 AM

Matt, great sleuthing.

I agree the

$out->addModuleStyles( 'mw.PopUpMediaTransform' );

is redundant, also probably

$out->addModuleStyles( 'mw.PopUpMediaTransform' );

for the similar parser hook.

TMH's BeforePageOutput hook loads 'mw.PopUpMediaTransform', which specifies the dependency on 'mw.MwEmbedSupport'. But MwEmbedSupport in addStartupModules() explicitly loads 'mw.MwEmbedSupport' and all the files that it depends on. I think none of that should be necessary with latest MediaWiki, maybe it's there for backward compatibility with 1.17. I submitted gerrit 92052.

Change 88943 merged by jenkins-bot:
Remove dialogFitWindow and jquery.ui.dialog from mwEmbedUtil

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

It looks like https://gerrit.wikimedia.org/r/88943 and https://gerrit.wikimedia.org/r/88944 have been merged. I suppose we're waiting on https://gerrit.wikimedia.org/r/92052 to be merged in order to mark this bug as resolved/fixed.

This will stop jquery.ui from loading by default on some WMF wikis. Specifically, those where only jquery.mwEmbedUtil depends on jquery.ui.dialog, and nothing else depends on the part of jquery.ui in question.

For gadgets and user scripts, they just need to declare their dependency, either using the gadget syntax or mw.loader.using. Scripts should do this in general.

However, I thought of another issue. If sites are using jquery.ui buttons in regular wikitext, that will also stop working unless jquery.ui.button is loaded some other way (e.g. English Wikipedia has ext.gadget.teahouse loaded by default, and it depends on jquery.ui.button).

See https://en.wikipedia.org/wiki/Template:Clickable_button_2 for an example of this in use.

This will roll out with 1.23wmf2, which means it hits the first non 'test' wiki on the 4th. I'll also send out an email to wikitech-ambassadors about this.

ori added a comment.Oct 31 2013, 5:02 AM

(In reply to comment #10)

This will stop jquery.ui from loading by default on some WMF wikis.
Specifically, those where only jquery.mwEmbedUtil depends on
jquery.ui.dialog,
and nothing else depends on the part of jquery.ui in question.

Well done! This is fantastic work.

(In reply to comment #7)

Matt, great sleuthing.

I agree the

$out->addModuleStyles( 'mw.PopUpMediaTransform' );

is redundant, [..]

TMH's BeforePageOutput hook loads 'mw.PopUpMediaTransform'
[..] I submitted Gerrit change #92052.

One thing to keep in mind when "fixing" issues like this is the styling if non-JavaScript elements (eg. PHP-served HTML output) as, unless position/top is set these modules will load async and would cause a FOUC.

Of course, that doesn't justify silly code that loads the stylesheet twice but it isn't always obvious that one can simply be removed.

Change 99597 had a related patch set uploaded by Ori.livneh:
Don't load mw.PopUpMediaTransform unconditionally

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

Change 99597 merged by jenkins-bot:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

Change 108649 had a related patch set uploaded by Ori.livneh:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

Change 108650 had a related patch set uploaded by Ori.livneh:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

Change 108649 merged by jenkins-bot:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

Change 108650 merged by jenkins-bot:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

All patches merged -> resetting status.

Is more work planned to do here, or shall this be closed as FIXED?

Marking FIXED. If another part is found and we want a bug, someone can re-open or file something more specific.

ori added a comment.Apr 20 2014, 11:02 PM

Not fixed: MwEmbedSupport.hooks.php still says "TODO look into loading this on-demand instead of all pages", as well it should. There is no reason for loading these modules on all pages: 'mw.MwEmbedSupport.style', 'jquery.triggerQueueCallback', 'Spinner', 'jquery.loadingSpinner', 'jquery.mwEmbedUtil', 'mw.MwEmbedSupport'.

Re-opening and bumping priority, for two reasons:

  1. It's a site performance issue. A longstanding one, but no less severe for it.
  2. The hook that it depends on the ResourceLoaderGetStartupModules hook, which is deprecated as of Ic48ad39c6.

Change 145584 had a related patch set uploaded by Gilles:
Load most of TMH and its dependencies on demand

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

Change 145583 had a related patch set uploaded by Gilles:
Load most of TMH and its dependencies on demand

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

Change 145584 merged by jenkins-bot:
Load most of TMH and its dependencies on demand

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

Change 145583 merged by jenkins-bot:
Load most of TMH and its dependencies on demand

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

Gilles moved this task from Untriaged to Done on the Multimedia board.Dec 4 2014, 10:11 AM
Gilles raised the priority of this task from "High" to "Unbreak Now!".
Gilles lowered the priority of this task from "Unbreak Now!" to "High".Dec 4 2014, 11:20 AM

Add Comment