Requests for comment/Minifier

This RFC aims to improve the minification ratio of MediaWiki's JavaScript resources.

Proposal
Our current minification library, JavaScriptMinifier is actually quite nice, as it combines a decent minification ratio with a very good performance, however we can do better, and two areas are especially important: mobile where every byte counts and VisualEditor which delivers a load of scripts.

I propose to replace standard minification with an UglifyJS based service on WMF.

Comparison of minification

 * All sizes are in kilobytes

Proof of concept
Code lives in Extension:Minifier and requires a core change to work.

How it will work
1 or more servers running the Node.js service with LVS and Varnish in front of them. Varnish would use consistent hashing to make sure that requests for minification of the same data will end up on the same server (minification requests contain MD5 hashes of data in their URLs). The minifier service itself maintains a queue, makes sure that simultaneous requests for minification of the same JS will result in work being done only once and has an LRU cache.

Improving performance
UglifyJS is slower than JavaScriptMinifier (minifying jQuery core takes 2.1s instead of 1.5 on my machine) so some measures might be needed to improve cache hit rate:
 * Minifier server will have its cache shared between all wikis.
 * Make memcached/APC cache keys global?
 * Already the case since MediaWiki 1.26.
 * Minify every module separately to avoid minifying all possible combinations of modules?
 * Already the case since MediaWiki 1.27alpha (september 2016, T107377).
 * Minify only module JS, not the messages. (To avoid cache invalidation upon localisation changes. This will also make minification of some modules a bit faster.)
 * Already the case since MediaWiki 1.26.