resourceloader: Combine base modules and page modules requests
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 12 Jul 2018 20:09:28 +0000 (13:09 -0700)
committerKrinkle <krinklemail@gmail.com>
Wed, 8 Aug 2018 02:56:50 +0000 (02:56 +0000)
commitdec800968eb618c1f8632df7be49783fc82078d2
tree58f1ed09c147bc9315161b45a2828a1a8896726f
parent4d3b6f213e1389fa1ef16690ed8fb49022c74336
resourceloader: Combine base modules and page modules requests

This commit implements step 4 and step 5 of the plan outlined at T192623.

Before this task began, the typical JavaScript execution flow was:

* HTML triggers request for startup module (js req 1).
* Startup module contains registry, site config, and triggers
  a request for the base modules (js req 2).
* After the base modules arrive (which define jQuery and mw.loader),
  the startup module invokes a callback that processes RLQ,
  which is what will request modules for this page (js req 3).

In past weeks, we have:

* Made mediawiki.js independent of jQuery.
* Spun off 'mediawiki.base' from mediawiki.js – for everything
  that wasn't needed for defining `mw.loader`.
* Moved mediawiki.js from the base module request to being embedded
  as part of startup.js.

The concept of dependencies is native to ResourceLoader, and thanks to the
use of closures in mw.loader.implement() responses, we can download any
number of interdependant modules in a single request (or parallel requests).
Then, when a response arrives, mw.loader takes care to pause or resume
execution as-needed. It is normal for ResourceLoader to batch several modules
together, including their dependencies.

As such, we can eliminate one of the two roundtrips required before a
page can request modules. Specifically, we can eliminate "js req 2" (above),
by making the two remaining base modules ("jquery" and "mediawiki.base") an
implied dependency for all other modules, which ResourceLoader will naturally
fetch and execute in the right order as part of the batch request.

Bug: T192623
Change-Id: I17cd13dffebd6ae476044d8d038dc3974a1fa176
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderStartUpModule.php
includes/specials/SpecialJavaScriptTest.php
maintenance/jsduck/eg-iframe.html
resources/Resources.php
resources/lib/jquery/jquery.migrate.js
resources/src/mediawiki.base/mediawiki.base.js
resources/src/startup/mediawiki.js
resources/src/startup/startup.js
tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js