ted serbinski – entrepreneur & web architect
  • thoughts
  • about
  • contact



Popular content

  • Backup your Mac the smart way!
  • New iPod
  • How to Save and Archive Your Geocities Account (with jQuery + Firebug)
  • "Orange Mint" Drupal theme for download
  • Preventing Drupal from Handling 404s for Performance
  • MothersClick Wins Niche Social Networking Category in Web 2.0 Awards
  • "Black & Blue" Drupal Theme Released
  • DC Drupal Meetup #5
  • Taking Naps with Pzizz
  • Great Show at the 9:30 Club
more

Recent comments

  • thanks very much
    1 week 3 days ago
  • it is really nice written
    2 weeks 2 days ago
  • Hi, I have used the
    4 weeks 14 hours ago
  • thankyou so much and for
    8 weeks 5 days ago
  • It’s typical for the
    10 weeks 2 days ago
more

Drupal Behavior to Fix IE6 CSS Background Image Flickering

When the new myLifetime community launched we wanted to focus on performance, and one trick was to minimize HTTP requests by using the CSS sprites technique. For a great run down of this technique and examples of other major sites using this, check out this resource on Smashing Magazine.

Double checking this implementation with YSlow! everything was working great.

Well almost. Then we tried IE6. I hate IE6.

Then I discovered this excellent post detailing IE6 and its BackgroundImageCache usage.

After trying that JS trick, we noticed the page was significantly faster & smoother in IE6. With heavy CSS sprite usage this was a necessary fix. And with future sites in the works with this same technique, seems like a reoccurring fix.

To Drupal-ize & jQuery-ize this fix for resuability, I wrote this simple behavior below that works with Drupal 6. You can see in action on the myLifetime community.

  1. /**
  2.  * Fix flickering background images in IE.
  3.  */
  4. Drupal.behaviors.fixIEFlickr = function() {
  5.   if (jQuery.browser.msie) {
  6.     try {
  7.       document.execCommand('BackgroundImageCache', false, true);
  8.     } catch(err) {}
  9.   }
  10. };

May this code save you a few hours/days of head banging!

posted 11 May 2009
  • css
  • drupal
  • ie6
  • jquery

5 comments

#1
Tostinni wrote 43 weeks 1 day ago

Hi Ted, I was curious regarding the fact that you didn’t use CSS/JS aggregation for your CSS/JS files, is it because you use a CDN (ltcdn.com) ? Thansk for sharing this tip.

#2
ted wrote 43 weeks 1 day ago

@Tostinni aggregation is usually on but sometimes the other engineers turn it off to debug some other caching issues with the CDN. No normal reason to have it off :) But the CDN does help greatly even if it is off.

#3
tostinni wrote 43 weeks 1 day ago

Thanks Ted, in fact I was suprised, by the speed of the site, in Opera display is blazzing fast so it wasn’t an issue having the CSS/JS files split. Bests

#4
Linda wrote 41 weeks 6 days ago

Hi Ted,

This solution sounds brilliant and just what I’m looking for!

I only have one problem….as a newbee in Drupal, I haven’t got any idea WHERE to put this code….. can you help me out?.... what file needs to be changed? Do I create a new module?

I would love to add a background-image to my site, but not if it flickers in IE!!

Thanks in advance,

Linda

#5
ted wrote 41 weeks 6 days ago

Linda a few background images should still work fine in IE6. If you are using a lot of them like in the above linked examples that is where you can run into issues.

To use this technique create a new JavaScript file and use your themes info file to include this script. You could also optionally add this in a module using drupal_add_js but that might be more work than is needed.

Add your comment

The content of this field is kept private and will not be shown publicly.
  • You can use Textile markup to format text.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <img> <pre>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options


Code examples and downloadable zip files of code are licensed under a Creative Commons License.
All other content, unless where noted, ©2010 Theodore Serbinski. All Rights Reserved.