diff -u b/includes/common.inc b/includes/common.inc --- b/includes/common.inc +++ b/includes/common.inc @@ -4428,7 +4428,7 @@ // See drupal_add_js() for details. $key = 'aggregate_' . $item['group'] . '_' . $item['every_page'] . '_' . $index; $processed[$key] = ''; - $files[$key][$item['data']] = $item; + $aggregate_files[$key][$item['data']] = $item; } break; @@ -4445,8 +4445,8 @@ } // Aggregate any remaining JS files that haven't already been output. - if ($preprocess_js && count($files) > 0) { - foreach ($files as $key => $file_set) { + if ($preprocess_js && count($aggregate_files) > 0) { + foreach ($aggregate_files as $key => $file_set) { $uri = drupal_build_js_cache($file_set); // Only include the file if was written successfully. Errors are logged // using watchdog. @@ -4456,6 +4456,9 @@ $js_element['#attributes']['src'] = $preprocess_file; $processed[$key] = theme('html_tag', array('element' => $js_element)); } + else { + unset($processed[$key]); + } } } @@ -5004,9 +5007,16 @@ foreach ($files as $path => $info) { if ($info['preprocess']) { // Append a ';' and a newline after each JS file to prevent them from running together. - $contents .= file_get_contents($path) . ";\n"; + if ($content = file_get_contents($path)) { + $contents .= $content . ";\n"; + } } } + + // Return if there's no content. + if (empty($contents)) { + return FALSE; + } // Prefix filename to prevent blocking by firewalls which reject files // starting with "ad*". $filename = 'js_' . drupal_hash_base64($contents) . '.js';