resourceloader: Add internal RLPAGEMODULES constant
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 17 Sep 2018 23:48:14 +0000 (00:48 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 18 Sep 2018 00:10:01 +0000 (01:10 +0100)
Expose this constant for internal use by Navigation Timing,
so that it can compute mwLoadEnd based on when these modules
finish loading.

The way mwLoadEnd is currently computed is by building a list
of all registered module names, and narrowing it down to the
ones in 'loading' state at the time that ext.navigationTiming.js
executes. The problem with doing that, is that it is includes
various lazy-loaded modules that aren't critical to the page and
aren't meant to be tracked by that metric. For example:

* Preloading of modules from various extensions (including VE,
  and Popups).
* Background chains for EventLogging schemas from mw.loader.using,
  including the one started by Navigation Timing itself.
  On my local install, the list of filtered down modules always
  includes 'schema.SaveTiming', '...rumSpeedIndex', etc.

Exporting the list passed to the initial load() call as constant
will enable Navigation Timing to instead only await only those
modules (and their dependneices).

Bug: T204426
Change-Id: Ida134b4dfee218db16c2d1f88d4f26e8d761e154

includes/resourceloader/ResourceLoaderClientHtml.php
tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php

index 8d08366..5c072bf 100644 (file)
@@ -304,7 +304,10 @@ class ResourceLoaderClientHtml {
                // Inline RLQ: Load general modules
                if ( $data['general'] ) {
                        $chunks[] = ResourceLoader::makeInlineScript(
-                               Xml::encodeJsCall( 'mw.loader.load', [ $data['general'] ] ),
+                               'RLPAGEMODULES='
+                                       . ResourceLoader::encodeJsonForScript( $data['general'] )
+                                       . ';'
+                                       . 'mw.loader.load(RLPAGEMODULES);',
                                $nonce
                        );
                }
index 7cd6983..dbc757f 100644 (file)
@@ -226,7 +226,7 @@ Deprecation message.' ]
                        . 'mw.config.set({"key":"value"});'
                        . 'mw.loader.state({"test.exempt":"ready","test.private":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.styles.deprecated":"ready","test.scripts":"loading"});'
                        . 'mw.loader.implement("test.private@{blankVer}",function($,jQuery,require,module){},{"css":[]});'
-                       . 'mw.loader.load(["test"]);'
+                       . 'RLPAGEMODULES=["test"];mw.loader.load(RLPAGEMODULES);'
                        . 'mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts\u0026only=scripts\u0026skin=fallback");'
                        . '});</script>' . "\n"
                        . '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.styles.deprecated%2Cpure&amp;only=styles&amp;skin=fallback"/>' . "\n"