Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. JsCollectionOptimizerLazy.php

function JsCollectionOptimizerLazy::optimizeGroup

Overrides AssetCollectionGroupOptimizerInterface::optimizeGroup

File

core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php, line 155

Class

JsCollectionOptimizerLazy
Optimizes JavaScript assets.

Namespace

Drupal\Core\Asset

Code

public function optimizeGroup(array $group) : string {
    $data = '';
    $current_license = FALSE;
    foreach ($group['items'] as $js_asset) {
        // Ensure license information is available as a comment after
        // optimization.
        if ($js_asset['license'] !== $current_license) {
            $data .= "/* @license " . $js_asset['license']['name'] . " " . $js_asset['license']['url'] . " */\n";
        }
        $current_license = $js_asset['license'];
        // Optimize this JS file, but only if it's not yet minified.
        if (isset($js_asset['minified']) && $js_asset['minified']) {
            $data .= file_get_contents($js_asset['data']);
        }
        else {
            $data .= $this->optimizer
                ->optimize($js_asset);
        }
        // Append a ';' and a newline after each JS file to prevent them from
        // running together.
        $data .= ";\n";
    }
    // Remove unwanted JS code that causes issues.
    return $this->optimizer
        ->clean($data);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal