On Sat, Apr 23, 2016 at 3:08 PM, Brion Vibber bvibber@wikimedia.org wrote:
Started as quick thoughts, turned into more of an essay, so I've posted the bulk on mediawiki.org:
https://www.mediawiki.org/wiki/User:Brion_VIBBER/ResourceLoader_and_latency
tl;dr summary:
On slow networks, latency in loading large JS and HTML resources means things don't always work right when we first see them.
If we take advantage of HTTP 2 we could skip the concatenation of separate ResourceLoader modules to reduce latency until each module _runs_, without adding _network_ latency.
Not so straight-forward. Khan Academy tried unbundling JavaScript on HTTP/2 page views last November and found that performance got worse. They attribute the regression primarily to the fact that bundling improves compression. They concluded that "it is premature to give up on bundling JavaScript files at this time, even for HTTP/2.0 clients."
(http://engineering.khanacademy.org/posts/js-packaging-http2.htm)
On most browsers, we take advantage of localStorage pretty heavily in order to have a durable cache of individual modules. Without it, slight variations in the module requirements would occasion re-downloading a lot of JavaScript, as the browser had no way of reusing JavaScript and CSS delivered under a different URL. (Service Workers now provide more sophisticated means of doing that, but global browser support is still only at 53%.
We had to disable localStorage caching in Firefox because of the way it manages quotas. Is your primary mobile browser Firefox for Android / iOS?
Lastly, we have good evidence that above-the-fold external CSS is a bigger contributor to page latency than JavaScript. Gabriel documented that pretty well in T124966 https://phabricator.wikimedia.org/T124966. That CSS is a bigger issue than JavaScript is not surprising (top-loaded CSS is render-blocking, whereas all of our JavaScript is loaded asynchronously), but the magnitude of its impact is impressive.
Krinkle is working on an arc of tasks that would get us there; T127328 https://phabricator.wikimedia.org/T127328 is the master task.