resourceloader: Add support for modules sending preload headers
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 18 Jul 2017 02:36:01 +0000 (21:36 -0500)
committerKrinkle <krinklemail@gmail.com>
Thu, 3 Aug 2017 03:57:00 +0000 (03:57 +0000)
commit3d342d4debe70e581e0ceaa03ee22f0a98c97392
treeb049770157680201dbbd4eea4baa1a125a7e5a1e
parenta6463be4c631220898a6af44a01dfa901af6130a
resourceloader: Add support for modules sending preload headers

ResourceLoaderModule objects gain a new method getPreloadLinks() which
returns an array with the meta data required to build a Link rel=preload
header according to the current draft for W3C Preload.
<https://w3c.github.io/preload/>

Another implementation of this is already in use in OutputPage for
preloading the logo image.

This array is formatted by the ResourceLoaderModule::getHeaders method,
which is implemented as "final" at this time, thus restricting use to
the Link rel=preload header.

Headers are exposed and process-cached, like all other content
(scripts, styles, etc.), through ResourceLoaderModule::getModuleContent,
and aggregated by ResoureLoader::makeModuleResponse.

I had hoped for the getPreloadLinks to be stateless (not vary on $context).
Whether something should be preloaded and what, should not vary on the
skin or language. However, while that conceptually holds true, the exact
url for any given resource may still vary. Even the main use case for this
feature (T164299, preloading base modules request) require $context to pass
down skin and lang to the load.php url.

Add full test coverage and example documentation.

Bug: T164299
Change-Id: I2bfe0796ceaa0c82579c501f5b10e931f2175681
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderModule.php
tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php