Drupal Overcome IE 31 stylesheet limit


/ Published in: PHP
Save to your folder(s)

To be placed in template.php preprocess_page function.\\r\\n\\r\\nBreaks stylesheets into 2 style tags with limit of 30 @imports each. IE has a limitation of 31 @imports or 31 style tags. (source: [http://john.albin.net/ie-css-limits/single-style-test.html](http://john.albin.net/ie-css-limits/single-style-test.html))


Copy this code and paste it in your HTML
  1. <?php
  2. // Consolidate all styles import into 1 style tag. Solves IE 31 style tag limit
  3. $styles_document = new DOMDocument();
  4. $styles_document->loadHTML($vars['styles']);
  5. $style_elements = $styles_document->getElementsByTagName('style');
  6. $stylesheets = '';
  7. $stylesheets2 = '';
  8.  
  9. for ($i=0;$i<$style_elements->length;$i++) {
  10. $stylesheets .= $style_elements->item($i)->nodeValue . "\n";
  11. if($i == 30) {break;}
  12. }
  13. $styles = '<style type="text/css" media="all">' . $stylesheets . "</style>\n";
  14.  
  15. for ($i=31;$i<$style_elements->length + 1;$i++) {
  16. $stylesheets2 .= $style_elements->item($i)->nodeValue . "\n";
  17. if($i == 60) {break;}
  18. }
  19. if($stylesheets2 != '') {
  20. $styles .= '<style type="text/css" media="all">' . $stylesheets2 . '</style>';
  21. }
  22. $vars['styles'] = $styles;
  23. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.