diff --git a/core/lib/Drupal/Core/Asset/AssetResolver.php b/core/lib/Drupal/Core/Asset/AssetResolver.php
index 9927049..eb89f72 100644
--- a/core/lib/Drupal/Core/Asset/AssetResolver.php
+++ b/core/lib/Drupal/Core/Asset/AssetResolver.php
@@ -114,10 +114,10 @@ protected function getLibrariesToLoad(AttachedAssetsInterface $assets) {
    * {@inheritdoc}
    */
   public function getCssAssets(AttachedAssetsInterface $assets, $optimize) {
-    $theme_info = $this->themeManager->getActiveTheme();
     // Add the theme name to the cache key since themes may implement
-    // hook_css_alter().
-    $cid = 'css:' . $theme_info->getName() . ':' . Crypt::hashBase64(serialize($assets)) . (int) $optimize;
+    // hook_library_info_alter().
+    $theme_info = $this->themeManager->getActiveTheme();
+    $cid = 'css:' . $theme_info->getName() . ':' .  Crypt::hashBase64(serialize($assets->getLibraries())) . (int) $optimize;
     if ($cached = $this->cache->get($cid)) {
       return $cached->data;
     }
@@ -187,9 +187,7 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize) {
    * Returns the JavaScript settings assets for this response's libraries.
    *
    * Gathers all drupalSettings from all libraries in the attached assets
-   * collection and merges them, then it merges individual attached settings,
-   * and finally invokes hook_js_settings_alter() to allow alterations of
-   * JavaScript settings by modules and themes.
+   * collection and merges them.
    *
    * @param \Drupal\Core\Asset\AttachedAssetsInterface $assets
    *   The assets attached to the current response.
@@ -207,9 +205,6 @@ protected function getJsSettingsAssets(AttachedAssetsInterface $assets) {
       }
     }
 
-    // Attached settings win over settings in libraries.
-    $settings = NestedArray::mergeDeepArray([$settings, $assets->getSettings()], TRUE);
-
     return $settings;
   }
 
@@ -217,11 +212,10 @@ protected function getJsSettingsAssets(AttachedAssetsInterface $assets) {
    * {@inheritdoc}
    */
   public function getJsAssets(AttachedAssetsInterface $assets, $optimize) {
-    $theme_info = $this->themeManager->getActiveTheme();
     // Add the theme name to the cache key since themes may implement
-    // hook_js_alter(). Additionally add the current language to support
-    // translation of JavaScript files.
-    $cid = 'js:' . $theme_info->getName() . ':' . $this->languageManager->getCurrentLanguage()->getId() . ':' .  Crypt::hashBase64(serialize($assets)) . (int) $optimize;
+    // hook_library_info_alter().
+    $theme_info = $this->themeManager->getActiveTheme();
+    $cid = 'js:' . $theme_info->getName() . ':' . Crypt::hashBase64(serialize($assets->getLibraries())) . (int) $optimize;
 
     if ($cached = $this->cache->get($cid)) {
       list($js_assets_header, $js_assets_footer, $settings, $settings_in_header) = $cached->data;
@@ -331,6 +325,9 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize) {
 
 
     if ($settings !== FALSE) {
+      // Attached settings override both library definitions and
+      // hook_js_settings_build().
+      $settings = NestedArray::mergeDeepArray([$settings, $assets->getSettings()], TRUE);
       // Allow modules and themes to alter the JavaScript settings.
       $this->moduleHandler->alter('js_settings', $settings, $assets);
       $this->themeManager->alter('js_settings', $settings, $assets);
