--- includes/_common.inc.original 2008-07-09 23:48:27.000000000 +0200 +++ includes/common.inc 2008-07-10 19:34:12.000000000 +0200 @@ -1688,6 +1688,9 @@ function drupal_get_css($css = NULL) { $no_theme_preprocess = ''; $preprocess_css = (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update')); + $group_css_files = variable_get('group_css_files', FALSE); + $group_css_limit = 30; + $directory = file_directory_path(); $is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC); @@ -1700,6 +1703,11 @@ function drupal_get_css($css = NULL) { foreach ($css as $media => $types) { // If CSS preprocessing is off, we still need to output the styles. // Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones. + if ($group_css_files) { + $no_module_preprocess_media = array(); + $no_theme_preprocess_media = array(); + $output_media = array(); + } foreach ($types as $type => $files) { if ($type == 'module') { // Setup theme overrides for module styles. @@ -1722,15 +1730,27 @@ function drupal_get_css($css = NULL) { // If a CSS file is not to be preprocessed and it's a module CSS file, it needs to *always* appear at the *top*, // regardless of whether preprocessing is on or off. if (!$preprocess && $type == 'module') { - $no_module_preprocess .= ''."\n"; + if ($group_css_files) { + $no_module_preprocess_media[] = '@import "'. base_path() . $file . $query_string .'";'; + } else { + $no_module_preprocess .= ''."\n"; + } } // If a CSS file is not to be preprocessed and it's a theme CSS file, it needs to *always* appear at the *bottom*, // regardless of whether preprocessing is on or off. else if (!$preprocess && $type == 'theme') { - $no_theme_preprocess .= ''."\n"; + if ($group_css_files) { + $no_theme_preprocess_media[] = '@import "'. base_path() . $file . $query_string .'";'; + } else { + $no_theme_preprocess .= ''."\n"; + } } else { - $output .= ''."\n"; + if ($group_css_files) { + $output_media[] = '@import "'. base_path() . $file . $query_string .'";'; + } else { + $output .= ''."\n"; + } } } } @@ -1740,7 +1760,77 @@ function drupal_get_css($css = NULL) { if ($is_writable && $preprocess_css) { $filename = md5(serialize($types) . $query_string) .'.css'; $preprocess_file = drupal_build_css_cache($types, $filename); - $output .= ''."\n"; + if ($group_css_files) { + $output_media[] = '@import "'. base_path() . $preprocess_file .'";'; + } else { + $output .= ''."\n"; + } + } + + if ($group_css_files && $no_module_preprocess_media) { + if ($group_css_limit > 0 ) { + $i = 1; + $importgroup = ''; + foreach ($no_module_preprocess_media as $importfile) { + $importgroup .= $importfile ."\n"; + if ($i < $group_css_limit) { + $i++; + } else { + $no_module_preprocess .= ''. "\n"; + $importgroup = ''; + $i = 1; + } + } + if (!empty($importgroup)) { + $no_module_preprocess .= ''. "\n"; + } + } else { + $no_module_preprocess .= ''. "\n"; + } + } + + if ($group_css_files && $no_theme_preprocess_media) { + if ($group_css_limit > 0 ) { + $i = 1; + $importgroup = ''; + foreach ($no_theme_preprocess_media as $importfile) { + $importgroup .= $importfile ."\n"; + if ($i < $group_css_limit) { + $i++; + } else { + $no_theme_preprocess .= ''. "\n"; + $importgroup = ''; + $i = 1; + } + } + if (!empty($importgroup)) { + $no_theme_preprocess .= ''. "\n"; + } + } else { + $no_theme_preprocess .= ''. "\n"; + } + } + + if ($group_css_files && $output_media) { + if ($group_css_limit > 0 ) { + $i = 1; + $importgroup = ''; + foreach ($output_media as $importfile) { + $importgroup .= $importfile ."\n"; + if ($i < $group_css_limit) { + $i++; + } else { + $output .= ''. "\n"; + $importgroup = ''; + $i = 1; + } + } + if (!empty($importgroup)) { + $output .= ''. "\n"; + } + } else { + $output .= ''. "\n"; + } } } --- modules/system/_system.admin.inc.original 2008-07-10 17:12:41.000000000 +0200 +++ modules/system/system.admin.inc 2008-07-10 19:15:18.000000000 +0200 @@ -1333,6 +1333,13 @@ function system_performance_settings() { '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('This option can interfere with module development and should only be enabled in a production environment.'), ); + $form['bandwidth_optimizations']['group_css_files'] = array( + '#type' => 'radios', + '#title' => t('Group CSS files'), + '#default_value' => intval(variable_get('group_css_files', FALSE)), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => '

'. t('Internet Explorer 6 and 7 ignore CSS stylesheets after 30 <style> or <link> tags (see Microsoft Knowledge Base 262161 and issue 228818 on drupal.org). By enabling this option up to 30 CSS files get grouped into single <style> tags per media type. It is recommended to enable this option in sites using more than 30 CSS stylesheets and if download method is set to private. Group CSS files is not needed and enabling this option will not have any effect if Optimize CSS files is enabled. But be aware that enabling this option will prevent stylesheets to get saved when "saving as a page" feature is used (see issue 145218 on drupal.org).', array('@url_kb' => 'http://support.microsoft.com/kb/262161/en-us', '@title_kb' => 'All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer', '@url_issue' => 'http://drupal.org/node/228818', '@title_issue' => 'IE: Stylesheets ignored after 30 link/style tags', '@url_issue2' => 'http://drupal.org/node/145218', '@title_issue2' => 'Use href instead of @import for CSS')) .'

', + ); $form['clear_cache'] = array( '#type' => 'fieldset',