Same name and namespace in other branches
  1. 6.0.x advagg_js_minify/jshrink.inc \JShrink\Minifier::minify() 1 commentaire
  2. 7.x-2.x advagg_js_compress/jshrink.inc \JShrink\Minifier::minify() 1 commentaire
  3. 8.x-2.x advagg_js_minify/jshrink.inc \JShrink\Minifier::minify() 1 commentaire
  4. 8.x-3.x advagg_js_minify/jshrink.inc \JShrink\Minifier::minify() 1 commentaire
  5. 8.x-4.x advagg_js_minify/jshrink.inc \JShrink\Minifier::minify() 1 commentaire

Takes a string containing javascript and removes unneeded characters in order to shrink the code without altering it's functionality.

Paramètres

string $js The raw javascript to be minified:

array $options Various runtime options in an associative array:

Return value

bool|string

Throws

\Exception

1 call to Minifier::minify()
JsMinifier::minifyJshrink dans advagg_js_minify/src/Asset/JsMinifier.php
Minify a JS string using jshrink.

Fichier

advagg_js_minify/jshrink.inc, line 145

Classe

Minifier
Minifier

Namespace

JShrink

Code

public static function minify($js, $options = array()) {
    try {
        ob_start();
        $jshrink = new Minifier();
        $js = $jshrink->lock($js);
        $jshrink->minifyDirectToOutput($js, $options);
        // Sometimes there's a leading new line, so we trim that out here.
        $js = ltrim(ob_get_clean());
        $js = $jshrink->unlock($js);
        unset($jshrink);
        return $js;
    } catch (\Exception $e) {
        if (isset($jshrink)) {
            // Since the breakdownScript function probably wasn't finished
            // we clean it out before discarding it.
            $jshrink->clean();
            unset($jshrink);
        }
        // without this call things get weird, with partially outputted js.
        ob_end_clean();
        throw $e;
    }
}