function JsCollectionOptimizer::generateHash

Same name in other branches
  1. 9 core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php \Drupal\Core\Asset\JsCollectionOptimizer::generateHash()
  2. 10 core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php \Drupal\Core\Asset\JsCollectionOptimizer::generateHash()

Generate a hash for a given group of JavaScript assets.

Parameters

array $js_group: A group of JavaScript assets.

Return value

string A hash to uniquely identify the given group of JavaScript assets.

1 call to JsCollectionOptimizer::generateHash()
JsCollectionOptimizer::optimize in core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php
The cache file name is retrieved on a page load via a lookup variable that contains an associative array. The array key is the hash of the names in $files while the value is the cache file name. The cache file is generated in two cases. First, if…

File

core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php, line 175

Class

JsCollectionOptimizer
Optimizes JavaScript assets.

Namespace

Drupal\Core\Asset

Code

protected function generateHash(array $js_group) {
    $js_data = [];
    foreach ($js_group['items'] as $js_file) {
        $js_data[] = $js_file['data'];
    }
    return hash('sha256', serialize($js_data));
}

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