…
上周接到一個需求,有人反饋淘寶的搜尋結果頁會對某些資源檔進行重複不停地重新載入,問題嚴重。經過一系列排查,最終發現問題所在:
IE6在window.onload(或類比的domready)時執行指令碼,會引發一些cache的問題:
- 問題1. 此時JS對dom進行渲染級的變動,如設定寬高、innerHTML等,會對元素的背景圖進行重新請求
- 問題2. 此時JS對多個Image元素設定同一src,此src會被請求多次
…
先來看下搜尋結果頁fix前後的對比:
- fix前 http://www.chencheng.org/test/srp-bug/demo.php (788 requests) (瀑布圖部分)
- fix後 http://www.chencheng.org/test/srp-bug/demo.php?fix (35 requests) (瀑布圖)
…
Tests:(加fix參數查看fix後效果,看完fix版再看未fix版需重啟瀏覽器)
問題1 Test:背景圖會被重複載入
http://www.chencheng.org/test/srp-bug/css-sprites-test.php
問題2 Test:佔位圖會被載入三次
http://www.chencheng.org/test/srp-bug/img-src-test.php
…
解決方案:
問題1. 在頁頭CSS加入如下代碼
html {zoom: expression(function(ele){ele.style.zoom = "1";document.execCommand("BackgroundImageCache", false, true);}(this));}
問題2. 沒找到什麼好方法,暫時只能避免,即:不在window.onload或domready時進行類似操作
…
參考文檔:
http://ajaxian.com/archives/no-more-ie6-background-flicker
http://www.fivesevensix.com/studies/ie6flicker/
http://blog.sina.com.cn/s/blog_49e464d80100fm9h.html
…
完