Same name in other branches
- 6.0.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::optimize()
- 8.x-3.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::optimize()
- 8.x-4.x advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::optimize()
Overrides SingleAssetOptimizerBase::optimize
Fichier
-
advagg_js_minify/
src/ Asset/ JsMinifier.php, line 34
Classe
- JsMinifier
- Optimizes a JavaScript asset.
Namespace
Drupal\advagg_js_minify\AssetCode
public function optimize($contents, array $asset, array $data) {
// Do nothing if js file minification is disabled.
if (!($minifier = $this->config
->get('minifier'))) {
return $contents;
}
// Do not re-minify if the file is already minified.
if ($this->isMinified($contents)) {
return $contents;
}
$this->clean($contents, $asset);
$contents_original = $contents;
$function = $this->getFunction($minifier);
if (!is_callable($function)) {
return $contents;
}
$arguments = [
&$contents,
$asset['data'],
];
call_user_func_array($function, $arguments);
$contents = trim($contents);
// Ensure that $data ends with ; or }.
if (strpbrk(substr(trim($contents), -1), ';})') === FALSE) {
$contents .= ';';
}
if (!$this->isMinificationSuccess($contents, $contents_original)) {
return $contents_original;
}
return $contents;
}