diff --git a/core/includes/ajax.inc b/core/includes/ajax.inc
index 8683ff9..ef1611e 100644
--- a/core/includes/ajax.inc
+++ b/core/includes/ajax.inc
@@ -240,10 +240,6 @@ function ajax_render($commands = array()) {
     // since the base page ought to have at least one JS file and one CSS file
     // loaded. It probably indicates an error, and rather than making the page
     // reload all of the files, instead we return no new files.
-    if (empty($_POST['ajax_page_state'][$type])) {
-      $items[$type] = array();
-    }
-    else {
       $function = 'drupal_add_' . $type;
       $items[$type] = $function();
       drupal_alter($type, $items[$type]);
@@ -258,9 +254,6 @@ function ajax_render($commands = array()) {
           unset($items[$type][$key]);
         }
       }
-      // Ensure that the page doesn't reload what it already has.
-      $items[$type] = array_diff_key($items[$type], $_POST['ajax_page_state'][$type]);
-    }
   }
 
   // Render the HTML to load these files, and add AJAX commands to insert this
@@ -285,7 +278,7 @@ function ajax_render($commands = array()) {
     $extra_commands[] = ajax_command_append('body', $scripts_footer);
   }
   if (!empty($extra_commands)) {
-    $commands = array_merge($extra_commands, $commands);
+    //$commands = array_merge($extra_commands, $commands);
   }
 
   // Now add a command to merge changes and additions to Drupal.settings.
diff --git a/core/misc/ajax.js b/core/misc/ajax.js
index ec9958d..528f013 100644
--- a/core/misc/ajax.js
+++ b/core/misc/ajax.js
@@ -297,19 +297,8 @@ Drupal.ajax.prototype.beforeSerialize = function (element, options) {
     options.data['ajax_html_ids[]'].push(this.id);
   });
 
-  // Allow Drupal to return new JavaScript and CSS files to load without
-  // returning the ones already loaded.
-  // @see ajax_base_page_theme()
-  // @see drupal_get_css()
-  // @see drupal_get_js()
   options.data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme;
   options.data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token;
-  for (var key in Drupal.settings.ajaxPageState.css) {
-    options.data['ajax_page_state[css][' + key + ']'] = 1;
-  }
-  for (var key in Drupal.settings.ajaxPageState.js) {
-    options.data['ajax_page_state[js][' + key + ']'] = 1;
-  }
 };
 
 /**
@@ -582,6 +571,23 @@ Drupal.ajax.prototype.commands = {
    * Command to set the settings that will be used for other commands in this response.
    */
   settings: function (ajax, response, status) {
+    // Load new files if required
+    if (response.settings.ajaxPageState) {
+      var $head = $('head');
+      var basePath = Drupal.settings.basePath;
+
+      var jsFiles = Drupal.ajax.fileDiff('js', response.settings);
+      for (var i = 0, il = jsFiles.length; i < il; i += 1) {
+        $head.append('<script type="text/javascript" src="' + Drupal.settings.basePath + jsFiles[i] +'"/>');
+      }
+
+      var cssFiles = Drupal.ajax.fileDiff('css', response.settings);
+      cssFiles = $.map(cssFiles, function (file) {
+        return '@import url(' + basePath + file + ');';
+      });
+      $head.append('<style type="text/css">' + cssFiles.join("\n") + '</style>');
+    }
+
     if (response.merge) {
       $.extend(true, Drupal.settings, response.settings);
     }
@@ -619,4 +625,25 @@ Drupal.ajax.prototype.commands = {
   }
 };
 
+/**
+ * Compare CSS and JS files between ajaxPageState changes.
+ */
+Drupal.ajax.fileDiff = function (type, settings) {
+  var currentFiles = Drupal.settings.ajaxPageState[type];
+  var fileList = settings.ajaxPageState[type];
+  var diff = [];
+  var i = null;
+
+  for (i in fileList) {
+    if (fileList.hasOwnProperty(i)) {
+      // check it's not already loaded
+      if (!currentFiles.hasOwnProperty(i)) {
+        diff.push(i);
+      }
+    }
+  }
+
+  return diff;
+};
+
 })(jQuery);
