You are here

public function JsOptimizer::clean in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Asset/JsOptimizer.php \Drupal\Core\Asset\JsOptimizer::clean()

Processes the contents of a javascript asset for cleanup.

Parameters

string $contents: The contents of the javascript asset.

Return value

string Contents of the javascript asset.

Overrides AssetOptimizerInterface::clean

File

core/lib/Drupal/Core/Asset/JsOptimizer.php, line 47

Class

JsOptimizer
Optimizes a JavaScript asset.

Namespace

Drupal\Core\Asset

Code

public function clean($contents) {

  // 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;
}