Same name and namespace in other branches
  1. 6.0.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::minifyJsqueeze() 1 commentaire
  2. 8.x-3.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::minifyJsqueeze() 1 commentaire
  3. 8.x-4.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::minifyJsqueeze() 1 commentaire

Minify a JS string using jsqueeze.

Paramètres

string $contents: Javascript string.

1 call to JsMinifier::minifyJsqueeze()
JsMinifier::minifyJsmin dans advagg_js_minify/src/Asset/JsMinifier.php
Minify a JS string using jsmin.

Fichier

advagg_js_minify/src/Asset/JsMinifier.php, line 276

Classe

JsMinifier
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_js_minify\Asset

Code

public function minifyJsqueeze(&$contents, $path = NULL) {
    $contents_before = $contents;
    // Only include jshrink.inc if the Patchwork\JSqueeze class doesn't exist.
    if (!class_exists('\\Patchwork\\JSqueeze')) {
        include drupal_get_path('module', 'advagg_js_minify') . '/jsqueeze.inc';
        $nesting_level = ini_get('xdebug.max_nesting_level');
        if (!empty($nesting_level) && $nesting_level < 200) {
            ini_set('xdebug.max_nesting_level', 200);
        }
    }
    ob_start();
    try {
        // Minify the contents of the aggregated file.
        // @codingStandardsIgnoreLine
        $jz = new \Patchwork\JSqueeze();
        $contents = $jz->squeeze($contents, TRUE, $this->config
            ->get('add_license'), FALSE);
        // Capture any output from JSqueeze.
        $error = trim(ob_get_contents());
        if (!empty($error)) {
            throw new \Exception($error);
        }
    } catch (\Exception $e) {
        // Log the JSqueeze exception and rollback to uncompressed content.
        $this->logger
            ->warning('JSqueeze had a possible error minifying: @file. Using uncompressed version. Error: ' . $e->getMessage(), [
            '@file' => $path,
        ]);
        $contents = $contents_before;
    }
    ob_end_clean();
}