Implemented Locally minify javascript

Jake B.

Well-known member
When going through and getting multiple products ready for release sometimes I end up hitting the limit of whatever service XF uses for minification and wind up getting the error

Code:
Server errors encountered while compiling:  Too many compiles performed recently.  Try again later.

It may be worthwhile adding the option for local compilation to happen rather than using a remote service with rate limiting.
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
You can do this by using custom build JSON -- you would be responsible for installing the necessary application on your build server though, which is the main reason why we just use an external service. (You can actually install Google's closure compiler locally; it's a JAR IIRC.)

I'm going to call this implemented based on that, though it's not totally seamless. Shipping that sort of thing with XF is unlikely to be something we'd do.
 
You can actually install Google's closure compiler locally; it's a JAR IIRC

Any way to make XF's system use that rather than connecting to their API without a custom build.json? If not (and it isn't something you guys are interested in adding) I may build this into our dev tools add-on
 
Haven't really looked deeply, but pretty sure it'd require a build.json.

Trying to track down how this is handled, what library is being used for Google Closure currently?

Edit: Nevermind, just found the service for it - not using a library just doing the http request with Guzzle
 
Won't let me edit my post again for some reason, but ended up extending \XF\Service\AddOn\JsMinifier and used this to compile locally to avoid the rate limiting:

Code:
<?php

namespace ThemeHouse\DevTools\XF\Service\AddOn;

class JsMinifier extends XFCP_JsMinifier
{

    public function minify()
    {
        $development = \XF::config('development');
        if (!empty($development['closureJar']) && file_exists($development['closureJar'])) {
            $closureJar = $development['closureJar'];

            passthru("java -jar {$closureJar} --js {$this->jsPath} --js_output_file {$this->minPath}", $returnVar);
            if ($returnVar !== 0) {
                throw new \ErrorException('Unable to minify ' . $this->jsPath);
            }

            return true;
        }

        return parent::minify();
    }
}

Just have to add $config['development']['closureJar'] to your config.php with a value of the path to your closure.jar that you download from Google. Probably not the best way to implement it, but it doesn't require any extra libraries to be loaded which is always nice :)
 
Back
Top Bottom