diff --git a/core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php b/core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php index 660d1a12a9..eaf259f79e 100644 --- a/core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php +++ b/core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php @@ -36,10 +36,17 @@ protected function generateHash(array $group): string { ]; foreach ($group['items'] as $key => $asset) { $normalized['asset_group']['items'][$key] = array_diff_key($asset, $group_keys, $omit_keys); + // If we are using the "Deployment identifier" (defined a settings.php + // file), then override the version with this identifier. This means + // that cache invalidation of the asset will happen when the deployment + // identifier changes. + if ($deployment_identifier = Settings::get('deployment_identifier')) { + $normalized['asset_group']['items'][$key]['version'] = $deployment_identifier; + } // If the version is set to -1, this means there is no version in the // library definition. To ensure unique hashes when unversioned files // change, replace the version with a hash of the file contents. - if ($asset['version'] === -1) { + elseif ($asset['version'] === -1) { $normalized['asset_group']['items'][$key]['version'] = hash('xxh64', file_get_contents($asset['data'])); } }