You are here

public function JsMinifier::clean in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 advagg_js_minify/src/Asset/JsMinifier.php \Drupal\advagg_js_minify\Asset\JsMinifier::clean()

Processes the contents of a javascript asset for cleanup.

Parameters

string $contents: The contents of the javascript asset.

array $asset: The core asset definition array.

Return value

string Contents of the javascript asset.

1 call to JsMinifier::clean()
JsMinifier::optimize in advagg_js_minify/src/Asset/JsMinifier.php
Optimize the asset's content.

File

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

Class

JsMinifier
Optimizes a JavaScript asset.

Namespace

Drupal\advagg_js_minify\Asset

Code

public function clean($contents, array $asset) {
  if ($encoding = Unicode::encodingFromBOM($contents)) {
    $contents = mb_substr(Unicode::convertToUtf8($contents, $encoding), 1);
  }
  elseif (isset($asset['attributes']['charset'])) {
    $contents = Unicode::convertToUtf8($contents, $asset['attributes']['charset']);
  }

  // Remove JS source and source mapping urls or these may cause 404 errors.
  $contents = preg_replace('/\\/\\/(#|@)\\s(sourceURL|sourceMappingURL)=\\s*(\\S*?)\\s*$/m', '', $contents);
  return $contents;
}