Same name in other branches
- 5.0.x src/Asset/SingleAssetOptimizerBase.php \Drupal\advagg\Asset\SingleAssetOptimizerBase::isMinificationSuccess()
- 6.0.x src/Asset/SingleAssetOptimizerBase.php \Drupal\advagg\Asset\SingleAssetOptimizerBase::isMinificationSuccess()
- 8.x-4.x src/Asset/SingleAssetOptimizerBase.php \Drupal\advagg\Asset\SingleAssetOptimizerBase::isMinificationSuccess()
Check if minification was successful before saving changes.
Parameters
string $minified: The minified asset contents.
string $original: The original asset contents to compare against.
Return value
bool TRUE for success.
2 calls to SingleAssetOptimizerBase::isMinificationSuccess()
- CssMinifier::optimize in advagg_css_minify/
src/ Asset/ CssMinifier.php - Optimize the asset's content.
- JsMinifier::optimize in advagg_js_minify/
src/ Asset/ JsMinifier.php - Optimize the asset's content.
File
-
src/
Asset/ SingleAssetOptimizerBase.php, line 115
Class
- SingleAssetOptimizerBase
- A base class for optimizing (especially minifying) assets.
Namespace
Drupal\advagg\AssetCode
protected function isMinificationSuccess($minified, $original) {
// If the minified data is zero length it was a failure.
if (empty($minified)) {
return FALSE;
}
// If set, make sure the minified version doesn't have a suspiciously high
// ratio or conversely a really low ratio.
if (!$this->config
->get('ratio_max')) {
return TRUE;
}
$before = strlen($original);
$after = strlen($minified);
$ratio = ($before - $after) / $before;
if ($ratio > $this->config
->get('ratio_max') || $ratio < $this->config
->get('ratio_min')) {
return FALSE;
}
return TRUE;
}