IE Background Cache Fix

A while back a lot of people where covering how to work around the bug that IE always reloads background images from the server, leading to your UI flickering. Dean wrote one and lots of others wrote the same thing. Today, I saw this simple workaround (from a fellow Googler who worked at Microsoft before):

document.execCommand("BackgroundImageCache", false, true)

Much simpler but makes me wonder why this is not the default setting?

9 Responses to “IE Background Cache Fix”

  1. Nicholas C. Zakas Says:

    I’ve actually wondered about this “bug” for a while. I’m sure somewhere along the line this decision was made for a logical reason…maybe they didn’t anticipate how much background images would be used, or maybe they thought there was some use case under which it would be desirable not to cache the background image. I’m generally not big on overriding things that seem to be design decisions (which this seems to be). I’ve never really thought this was a “bug”…bugs don’t usually have switches that say “turn off bug”. :)

  2. Thomas Frank Says:

    Brilliant :-D, though it has been mentioned before:
    http://www.mister-pixel.com/#Content__state=is_that_simple

    @Nicholas:
    I agree - it’s not a bug.
    It’s yet another Microsoft conspiracy ;-), revealed here:
    http://www.bazon.net/mishoo/articles.epl?art_id=958#gen5

  3. Erik Arvidsson Says:

    It is fixed in IE7 by the way so I would definitely call this a bug. A bug by design :-)

    Thomas: I saw that this had been mentioned before but since I didn’t know about it before I thought I would spread the word.

  4. Quick fix for annoying bug in Internet Explorer 6 – Interaction Design Blog Says:

    [...] IE Background Cache Fix on erik’s weblog [...]

  5. Patrick Corcoran Says:

    This is a helpful tip.

    I have noticed only one problem with this, and it seems to occur in IE6 on Windows Server 2003 platforms. The execCommand fails and throws an “Invalid Argument” error.

    A try/catch around the command seems to do the trick.

  6. Pai Says:

    I am a new to Programming and held up with this issue….. I got an image as a background image for my header.(header is 10% of my screen). when ever the page refreshes and gets time to load, i see that the image missing giving the user a feel that it is not there.Once the page is loaded completely it appears again. I tried the above solution by giving that code in my onload function. But it didnt help. can any one help me to solve this?

  7. Erik Arvidsson Says:

    Yeah, at Google we use a try catch around it for exactly that reason.

  8. Nir Segev Says:

    Having the same issue with a map on aspx page, with update panel located on the same page.
    every time the update panel being updated the map flickers,
    does anyone know a way to prevent this from happening?
    I am using IE7

  9. pl Says:

    It does not work, if you change css dinamicly (menu for example).
    To prevent this, add any tag with your style and set it invisible.

    imho, if there is no element uses any style, IE will download background image every time element with this style appears.

Leave a Reply