Skip to content

Commit

Permalink
Merge pull request #979 from UN-OCHA/develop
Browse files Browse the repository at this point in the history
Deploy 28-08-2024
  • Loading branch information
lazysoundsystem authored Aug 27, 2024
2 parents 4e7a42f + 49fb2e2 commit e2bdae5
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 145 deletions.
53 changes: 53 additions & 0 deletions PATCHES/core_js_optimizer.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php
index 647a2c36a017f890c0e43bbdb350084989b1a7f1..3912afe5a9feeaae235c640cd89816091c7e97be 100644
--- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php
+++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizerLazy.php
@@ -155,24 +155,32 @@ public function deleteAll() {
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);
+
+ // No preprocessing, single JS asset: just use the existing URI.
+ if ($group['type'] === 'file' && !$group['preprocess']) {
+ $data = file_get_contents($group['items'][0]['data']);
+ }
+ else {
+ 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";
}
- // 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);
}
Loading

0 comments on commit e2bdae5

Please sign in to comment.