diff --git a/core/includes/common.inc b/core/includes/common.inc
index 84c3644..59e296a 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -2311,7 +2311,7 @@ function drupal_js_defaults($data = NULL) {
  * @see locale_js_alter()
  * @see drupal_js_defaults()
  */
-function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALSE) {
+function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALSE, Request $request = NULL) {
   if (!isset($javascript)) {
     $javascript = drupal_add_js();
   }
@@ -2339,10 +2339,10 @@ function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALS
     // this is an AJAX request.
     // @todo Clean up container call.
     $container = drupal_container();
-    if ($container->has('content_negotiation') && $container->isScopeActive('request')) {
-      $type = $container->get('content_negotiation')->getContentType($container->get('request'));
+    if (($container->has('content_negotiation') && $container->isScopeActive('request') && $request = $container->get('request')) || $request) {
+      $type = $container->get('content_negotiation')->getContentType($request);
     }
-    if (!empty($items['settings']) || (!empty($type) && $type == 'ajax')) {
+    if (!empty($items['settings']) || (!empty($type) && in_array($type, array('ajax', 'drupal_ajax', 'drupal_modal', 'drupal_dialog')))) {
       global $theme_key;
       // Provide the page with information about the theme that's used, so that
       // a later AJAX request can be rendered using the same theme.
diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponse.php b/core/lib/Drupal/Core/Ajax/AjaxResponse.php
index 2a72267..3c12860 100644
--- a/core/lib/Drupal/Core/Ajax/AjaxResponse.php
+++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php
@@ -111,8 +111,8 @@ protected function ajaxRender(Request $request) {
       unset($items['js']['settings']);
     }
     $styles = drupal_get_css($items['css'], TRUE);
-    $scripts_footer = drupal_get_js('footer', $items['js'], TRUE);
-    $scripts_header = drupal_get_js('header', $items['js'], TRUE);
+    $scripts_footer = drupal_get_js('footer', $items['js'], TRUE, $request);
+    $scripts_header = drupal_get_js('header', $items['js'], TRUE, $request);
 
     // Prepend commands to add the resources, preserving their relative order.
     $resource_commands = array();
