Loading core/lib/Drupal/Core/Asset/AssetResolver.php +49 −41 Original line number Diff line number Diff line Loading @@ -146,10 +146,14 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize, Languag 'preprocess' => TRUE, ]; foreach ($libraries_to_load as $library) { foreach ($libraries_to_load as $key => $library) { [$extension, $name] = explode('/', $library, 2); $definition = $this->libraryDiscovery->getLibraryByName($extension, $name); if (isset($definition['css'])) { if (empty($definition['css'])) { unset($libraries_to_load[$key]); continue; } foreach ($definition['css'] as $options) { $options += $default_options; // Copy the asset library license information to each file. Loading @@ -168,7 +172,6 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize, Languag $css[$options['data']] = $options; } } } // Allow modules and themes to alter the CSS assets. $this->moduleHandler->alter('css', $css, $assets, $language); Loading @@ -179,7 +182,7 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize, Languag uasort($css, [static::class, 'sort']); if ($optimize) { $css = \Drupal::service('asset.css.collection_optimizer')->optimize($css, $libraries_to_load, $language); $css = \Drupal::service('asset.css.collection_optimizer')->optimize($css, array_values($libraries_to_load), $language); } } $this->cache->set($cid, $css, CacheBackendInterface::CACHE_PERMANENT, ['library_info']); Loading Loading @@ -246,14 +249,21 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize, Language ]; // Collect all libraries that contain JS assets and are in the header. // Also remove any libraries with no JavaScript from the libraries to // load. $header_js_libraries = []; foreach ($libraries_to_load as $library) { foreach ($libraries_to_load as $key => $library) { [$extension, $name] = explode('/', $library, 2); $definition = $this->libraryDiscovery->getLibraryByName($extension, $name); if (isset($definition['js']) && !empty($definition['header'])) { if (empty($definition['js'])) { unset($libraries_to_load[$key]); continue; } if (!empty($definition['header'])) { $header_js_libraries[] = $library; } } $libraries_to_load = array_values($libraries_to_load); // The current list of header JS libraries are only those libraries that // are in the header, but their dependencies must also be loaded for them // to function correctly, so update the list with those. Loading @@ -262,7 +272,6 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize, Language foreach ($libraries_to_load as $library) { [$extension, $name] = explode('/', $library, 2); $definition = $this->libraryDiscovery->getLibraryByName($extension, $name); if (isset($definition['js'])) { foreach ($definition['js'] as $options) { $options += $default_options; // Copy the asset library license information to each file. Loading @@ -285,7 +294,6 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize, Language $javascript[$options['data']] = $options; } } } // Allow modules and themes to alter the JavaScript assets. $this->moduleHandler->alter('js', $javascript, $assets, $language); Loading core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php +4 −4 Original line number Diff line number Diff line Loading @@ -26,8 +26,8 @@ public function testFrontAndRecipesPages() { $performance_data = $this->doRequests(); $this->assertSame(4, $performance_data->getStylesheetCount()); $this->assertLessThan(82500, $performance_data->getStylesheetBytes()); $this->assertSame(2, $performance_data->getScriptCount()); $this->assertLessThan(14500, $performance_data->getScriptBytes()); $this->assertSame(1, $performance_data->getScriptCount()); $this->assertLessThan(7500, $performance_data->getScriptBytes()); } /** Loading @@ -40,8 +40,8 @@ public function testFrontAndRecipesPagesAuthenticated() { $performance_data = $this->doRequests(); $this->assertSame(4, $performance_data->getStylesheetCount()); $this->assertLessThan(89500, $performance_data->getStylesheetBytes()); $this->assertSame(2, $performance_data->getScriptCount()); $this->assertLessThan(265000, $performance_data->getScriptBytes()); $this->assertSame(1, $performance_data->getScriptCount()); $this->assertLessThan(132500, $performance_data->getScriptBytes()); } /** Loading Loading
core/lib/Drupal/Core/Asset/AssetResolver.php +49 −41 Original line number Diff line number Diff line Loading @@ -146,10 +146,14 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize, Languag 'preprocess' => TRUE, ]; foreach ($libraries_to_load as $library) { foreach ($libraries_to_load as $key => $library) { [$extension, $name] = explode('/', $library, 2); $definition = $this->libraryDiscovery->getLibraryByName($extension, $name); if (isset($definition['css'])) { if (empty($definition['css'])) { unset($libraries_to_load[$key]); continue; } foreach ($definition['css'] as $options) { $options += $default_options; // Copy the asset library license information to each file. Loading @@ -168,7 +172,6 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize, Languag $css[$options['data']] = $options; } } } // Allow modules and themes to alter the CSS assets. $this->moduleHandler->alter('css', $css, $assets, $language); Loading @@ -179,7 +182,7 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize, Languag uasort($css, [static::class, 'sort']); if ($optimize) { $css = \Drupal::service('asset.css.collection_optimizer')->optimize($css, $libraries_to_load, $language); $css = \Drupal::service('asset.css.collection_optimizer')->optimize($css, array_values($libraries_to_load), $language); } } $this->cache->set($cid, $css, CacheBackendInterface::CACHE_PERMANENT, ['library_info']); Loading Loading @@ -246,14 +249,21 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize, Language ]; // Collect all libraries that contain JS assets and are in the header. // Also remove any libraries with no JavaScript from the libraries to // load. $header_js_libraries = []; foreach ($libraries_to_load as $library) { foreach ($libraries_to_load as $key => $library) { [$extension, $name] = explode('/', $library, 2); $definition = $this->libraryDiscovery->getLibraryByName($extension, $name); if (isset($definition['js']) && !empty($definition['header'])) { if (empty($definition['js'])) { unset($libraries_to_load[$key]); continue; } if (!empty($definition['header'])) { $header_js_libraries[] = $library; } } $libraries_to_load = array_values($libraries_to_load); // The current list of header JS libraries are only those libraries that // are in the header, but their dependencies must also be loaded for them // to function correctly, so update the list with those. Loading @@ -262,7 +272,6 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize, Language foreach ($libraries_to_load as $library) { [$extension, $name] = explode('/', $library, 2); $definition = $this->libraryDiscovery->getLibraryByName($extension, $name); if (isset($definition['js'])) { foreach ($definition['js'] as $options) { $options += $default_options; // Copy the asset library license information to each file. Loading @@ -285,7 +294,6 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize, Language $javascript[$options['data']] = $options; } } } // Allow modules and themes to alter the JavaScript assets. $this->moduleHandler->alter('js', $javascript, $assets, $language); Loading
core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php +4 −4 Original line number Diff line number Diff line Loading @@ -26,8 +26,8 @@ public function testFrontAndRecipesPages() { $performance_data = $this->doRequests(); $this->assertSame(4, $performance_data->getStylesheetCount()); $this->assertLessThan(82500, $performance_data->getStylesheetBytes()); $this->assertSame(2, $performance_data->getScriptCount()); $this->assertLessThan(14500, $performance_data->getScriptBytes()); $this->assertSame(1, $performance_data->getScriptCount()); $this->assertLessThan(7500, $performance_data->getScriptBytes()); } /** Loading @@ -40,8 +40,8 @@ public function testFrontAndRecipesPagesAuthenticated() { $performance_data = $this->doRequests(); $this->assertSame(4, $performance_data->getStylesheetCount()); $this->assertLessThan(89500, $performance_data->getStylesheetBytes()); $this->assertSame(2, $performance_data->getScriptCount()); $this->assertLessThan(265000, $performance_data->getScriptBytes()); $this->assertSame(1, $performance_data->getScriptCount()); $this->assertLessThan(132500, $performance_data->getScriptBytes()); } /** Loading