Minify a JS string using jsqueeze.

Paramètres

string $contents: Javascript string.

array $asset: An asset.

bool $log_errors: FALSE to disable logging to watchdog on failure.

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

Fichier

advagg_js_minify/src/Asset/JsOptimizer.php, line 431

Classe

JsOptimizer
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_js_minify\Asset

Code

public function minifyJsqueeze(&$contents, array $asset, $log_errors = TRUE) {
    $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.
        $jz = new \Patchwork\JSqueeze();
        $contents = $jz->squeeze($contents, TRUE, !\Drupal::config('advagg_js_minify.settings')->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.
        if ($log_errors) {
            $this->logger
                ->warning('JSqueeze error, skipping file. ' . $e->getMessage() . '<pre>' . $contents_before . '</pre>', []);
        }
        $contents = $contents_before;
    }
    ob_end_clean();
}