function JsOptimizer::clean

Same name in other branches
  1. 9 core/lib/Drupal/Core/Asset/JsOptimizer.php \Drupal\Core\Asset\JsOptimizer::clean()
  2. 8.9.x core/lib/Drupal/Core/Asset/JsOptimizer.php \Drupal\Core\Asset\JsOptimizer::clean()
  3. 10 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 80

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.