[ Pull request ]
I've recently published a few updates to the minifiers bundled with s9e\TextFormatter. When I started I didn't know that Flarum was using them for files that aren't related to the library but the latest changes should benefit it. In no particular order, here are those changes and how they relate to Flarum.
First, I added a meta-minifier called FirstAvailable. It's not a minifier itself, it holds a collection of minifiers that are executed in order and returns the result of the first successful minification. You can set up your preferred minifier first and set up a backup for it if it fails, and a backup for that, and so on.
I saw that Flarum used Matthias Mullie's Minify as a failsafe. I've always intended to add a native PHP minifier but never had the time to look into them. I ran my test suite (719 tests) minified with Minify and it worked fine so I've added support for it via the library's minifiers.
The reason I started working on minifiers is because I wanted to try a new approach, an alternative to the Closure Compiler service. The CCS's API is not very efficient from a network standpoint. The original source has to be sent URL-encoded, the response is sent encoded in JSON and the service doesn't seem to support gzip. I created a web service (repository here) with a more efficient API (no URL/JSON encoding, gzip support for both request and response) and a minifier that communicates with it. The name of the minifier is HostedMinifier. I currently host an instance of the webservice running on a free OpenShift instance.
The main benefit of running your own minifier service is not the more efficient API though. The time spent on networking is only a small fraction of the cost; Google's service runs on better hardware with a faster JVM, so it will generally be faster than a custom server. The real benefit is that since you will only minify a handful of different files/configuration, the web service can cache the result of the minification and reuse it. A cache hit will only take a few milliseconds to be served, regardless of the size of the code being minified. On top of that I've added another minifier, RemoteCache, which is meant to be used alongside (and in front of) the HostedMinifier minifier. Its purpose is to contact the same web service and test whether the code exists in its cache without sending the code itself, only sending a hash. On a cache hit, it's a big win. On a cache miss, you waste a network round-trip. Since Flarum minifies more or less the same files every time, it should have a pretty high hit ratio.
TL;DR: new minifiers are available. Two of them work as caching proxies or some sort of globally shared cache living in the cloud. I'd expect them to work better than the ClosureCompilerService minifier on slow networks. Oh and also there's a new HTTP client that supports persistent connections if you have cURL installed. Since Flarum minifies a bunch of files in a row, it can shave a couple of seconds off a full rebuild.