=== modified file 'includes/common.inc'
--- includes/common.inc	2009-03-17 22:35:07 +0000
+++ includes/common.inc	2009-03-21 19:57:14 +0000
@@ -4243,3 +4243,53 @@
   }
   variable_set('css_js_query_string', $new_character . substr($string_history, 0, 19));
 }
+
+class FunctionCallRecorder {
+  protected $calls = array();
+  protected $immediate_execution;
+
+  public function __construct($immediate_execution = FALSE) {
+    $this->immediate_execution = $immediate_execution;
+  }
+
+  public function add($name, $parameters) {
+    $this->calls[] = array('name' => $name, 'parameters' => $parameters);
+
+    if ($this->immediate_execution) {
+      call_user_func_array($name, $parameters);
+    }
+
+    return $this;
+  }
+
+  public function replay() {
+    foreach ($this->calls as $function) {
+      call_user_func_array($function['name'], $function['parameters']);
+    }
+  }
+}
+
+class CSSRecorder extends FunctionCallRecorder {
+  public function add() {
+    $arguments = func_get_args();
+    return parent::add('drupal_add_css', $arguments);
+  }
+}
+
+class JSRecorder extends FunctionCallRecorder {
+  public function add() {
+    $arguments = func_get_args();
+    return parent::add('drupal_add_js', $arguments);
+  }
+}
+
+function drupal_record($type = 'generic') {
+  switch ($type) {
+    case 'js':
+      return new JSRecorder();
+    case 'css':
+      return new CSSRecorder();
+    default:
+      return new FunctionCallRecorder(TRUE);
+  }
+}
\ No newline at end of file

=== modified file 'includes/form.inc'
--- includes/form.inc	2009-03-14 20:13:26 +0000
+++ includes/form.inc	2009-03-21 20:13:16 +0000
@@ -2330,6 +2330,13 @@
  * @ingroup themeable
  */
 function theme_form($element) {
+  // Ensure that CSS and JavaScript is added, even for cached forms.
+  foreach(array('css', 'js') as $type) {
+    if (isset($element['#' . $type]) && $element['#' . $type] instanceof FunctionCallRecorder) {
+      $element['#' . $type]->replay();
+    }
+  }
+
   // Anonymous div to satisfy XHTML compliance.
   $action = $element['#action'] ? 'action="' . check_url($element['#action']) . '" ' : '';
   return '<form ' . $action . ' accept-charset="UTF-8" method="' . $element['#method'] . '" id="' . $element['#id'] . '"' . drupal_attributes($element['#attributes']) . ">\n<div>" . $element['#children'] . "\n</div></form>\n";

=== modified file 'includes/theme.inc'
--- includes/theme.inc	2009-02-22 17:55:28 +0000
+++ includes/theme.inc	2009-03-21 20:14:18 +0000
@@ -2041,6 +2041,13 @@
   $variables['block_zebra'] = ($block_counter[$variables['block']->region] % 2) ? 'odd' : 'even';
   $variables['block_id'] = $block_counter[$variables['block']->region]++;
 
+  // Ensure that CSS and JavaScript is added, even for cached blocks.
+  foreach(array('css', 'js') as $type) {
+    if (isset($variables['block']->$type)) {
+      $variables['block']->$type->replay();
+    }
+  }
+
   $variables['template_files'][] = 'block-' . $variables['block']->region;
   $variables['template_files'][] = 'block-' . $variables['block']->module;
   $variables['template_files'][] = 'block-' . $variables['block']->module . '-' . $variables['block']->delta;

