我们在设计网页的时候会经常用到背景图片。有时候页面已经打开了,这些图片实际上已经download到本地了,但IE还是会试图再次请求下载这些图片,导致页面要加载半天才能载入进来,这样无疑增加Http Requests,容易导致用户浏览的页面表示不够友好,消耗大量服务器的带宽,给服务器带来很大的压力。

下面这段JS代码就是用来解决这个IE的BUG的。

  1. /**   
  2. * bug to fix: Flickering CSS Background Images in IE6   
  3. * conditions: when IE’s cache settings are “Every visit to the page” (a common developer’s setting)   
  4. **/   
  5. if (/*@cc_on @_jscript_version === 5.6 || @*/false) {
  6.     try { 
  7.         document.execCommand("BackgroundImageCache", false, true);
  8.     } catch(err) {}
  9. }