Optimize how user options are delivered to the client
authorOri Livneh <ori@wikimedia.org>
Thu, 4 Dec 2014 07:37:56 +0000 (23:37 -0800)
committerKrinkle <krinklemail@gmail.com>
Fri, 5 Dec 2014 19:36:45 +0000 (19:36 +0000)
commit1c1734758056005413dffe9859c72604231ecd9f
tree869df98f69895ef9fd2cf865a17043990184237a
parent5f04912af18ee4b2573735f12de5b449673efcab
Optimize how user options are delivered to the client

We currently embed the full set of user options in a <script> tag in the HTML
output of every page. This is grossly inefficient, because the full set of
options is usually largely made up of site defaults which the user hasn't
customized.

So instead of doing that, let's emit the default options using one
ResourceLoader module and then apply the user's customizations on top.

This has the effect of slightly increasing the total bytes of JavaScript code
(because options that the user has customized will be emitted twice: once with
their default value in the user.defaults module, and then again with the
customized value in user.options). But this is more than offset by the
fact that the bulk of user options code (~4 kB uncompressed on enwiki) becomes
cacheable across requests.

Bonus round:
* Varnish gets to cache 4 kB fewer per page.
* Changes to the default options don't take 30 days to propagate.

Change-Id: I5a7e258d2d69159381bf5cc363227088b8fd6019
autoload.php
includes/User.php
includes/resourceloader/ResourceLoaderUserDefaultsModule.php [new file with mode: 0644]
includes/resourceloader/ResourceLoaderUserOptionsModule.php
resources/Resources.php