IE圖片緩存document.execCommand("BackgroundImageCache",false,true)
更新時(shí)間:2011年03月01日 16:43:46 作者:
IE6下設(shè)置背景圖片是不會(huì)被真正cache住的,就算服務(wù)器做了cache,如果想cache住只能
Pixy方法受到IE的cache bug影響會(huì)閃爍。其實(shí)并沒有說清楚這個(gè)問題,但其實(shí)該bug是有條件的,即IE的cache設(shè)置為Every visit to the page,而不是默認(rèn)的Automatically?;旧希挥虚_發(fā)者才會(huì)把cache設(shè)置為每次訪問檢查更新,所以這個(gè)bug其實(shí)不會(huì)影響真正的用戶 (根據(jù)在winxpsp2的ie6下測(cè)試,雖然可能仍然調(diào)用了一次網(wǎng)絡(luò)存取的api,但是并沒有發(fā)生實(shí)際的請(qǐng)求,癥狀就是鼠標(biāo)有極短時(shí)間的抖動(dòng),但是圖像 不會(huì)閃爍)。此外有人發(fā)現(xiàn)了一個(gè)未公開的方法來讓IE對(duì)背景圖進(jìn)行緩存: document.execCommand("BackgroundImageCache",false,true)
用這種方法甚至避免了api調(diào)用,貌似是直接緩存在IE內(nèi)存中。
IE6下設(shè)置背景圖片是不會(huì)被真正cache住的,就算服務(wù)器做了cache,如果想cache住只能~~~
做過UI設(shè)計(jì)和開發(fā)的人一定知道,IE(不包括IE7)會(huì)經(jīng)常從服務(wù)器端重新載入背景圖片,好端端的UI界面在IE(不包括IE7)中就這樣被折騰著......
Erik發(fā)現(xiàn)了一個(gè)簡(jiǎn)單的解決辦法(針對(duì)IE7以下的IE有效,其實(shí)在IE7中已經(jīng)修復(fù)了這個(gè)Bug)
程序代碼
document.execCommand("BackgroundImageCache", false, true);
今天閱讀Ext的源碼時(shí)發(fā)現(xiàn)Jack Slocum已經(jīng)考慮到了這一點(diǎn),在Ext.js中給出了他的實(shí)現(xiàn),在其它Ajax框架中應(yīng)該還沒有這種類似的代碼,從這一個(gè)細(xì)節(jié)上就能看出Ext的全面~
程序代碼
var isIE = ua.indexOf("msie") > -1, isIE7 = ua.indexOf("msie 7") > -1;
// remove css image flicker
if(isIE && !isIE7){
try{
document.execCommand("BackgroundImageCache", false, true);
}catch(e){}
}
今 天閱讀幻宇的dreamplayer播放器源碼時(shí)發(fā)現(xiàn)幻宇也針對(duì)IE的背景緩存進(jìn)行了修復(fù),只是他并沒考慮到IE7中已經(jīng)不存在這個(gè)現(xiàn)象了,這是 evml.js中的一段相關(guān)代碼~(順便嘀咕兩句:這家伙,寫JS從來不加分號(hào)的,以前是這樣,現(xiàn)在還是這樣,這樣的話怎么進(jìn)行壓縮呀,汗~下面的代碼按 照我的習(xí)慣都已加上分號(hào),哪怕只有兩三句而已~)
程序代碼
window.isIE=navigator.appName.indexOf("Microsoft")==0;
if(isIE){
document.documentElement.addBehavior("#default#userdata");
document.execCommand("BackgroundImageCache",false,true);
}
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?
/**
* 相關(guān)回復(fù)
* by Nicholas C. Zakas @2007-02-26
*/
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".
用這種方法甚至避免了api調(diào)用,貌似是直接緩存在IE內(nèi)存中。
IE6下設(shè)置背景圖片是不會(huì)被真正cache住的,就算服務(wù)器做了cache,如果想cache住只能~~~
做過UI設(shè)計(jì)和開發(fā)的人一定知道,IE(不包括IE7)會(huì)經(jīng)常從服務(wù)器端重新載入背景圖片,好端端的UI界面在IE(不包括IE7)中就這樣被折騰著......
Erik發(fā)現(xiàn)了一個(gè)簡(jiǎn)單的解決辦法(針對(duì)IE7以下的IE有效,其實(shí)在IE7中已經(jīng)修復(fù)了這個(gè)Bug)
程序代碼
復(fù)制代碼 代碼如下:
document.execCommand("BackgroundImageCache", false, true);
今天閱讀Ext的源碼時(shí)發(fā)現(xiàn)Jack Slocum已經(jīng)考慮到了這一點(diǎn),在Ext.js中給出了他的實(shí)現(xiàn),在其它Ajax框架中應(yīng)該還沒有這種類似的代碼,從這一個(gè)細(xì)節(jié)上就能看出Ext的全面~
程序代碼
復(fù)制代碼 代碼如下:
var isIE = ua.indexOf("msie") > -1, isIE7 = ua.indexOf("msie 7") > -1;
// remove css image flicker
if(isIE && !isIE7){
try{
document.execCommand("BackgroundImageCache", false, true);
}catch(e){}
}
今 天閱讀幻宇的dreamplayer播放器源碼時(shí)發(fā)現(xiàn)幻宇也針對(duì)IE的背景緩存進(jìn)行了修復(fù),只是他并沒考慮到IE7中已經(jīng)不存在這個(gè)現(xiàn)象了,這是 evml.js中的一段相關(guān)代碼~(順便嘀咕兩句:這家伙,寫JS從來不加分號(hào)的,以前是這樣,現(xiàn)在還是這樣,這樣的話怎么進(jìn)行壓縮呀,汗~下面的代碼按 照我的習(xí)慣都已加上分號(hào),哪怕只有兩三句而已~)
程序代碼
復(fù)制代碼 代碼如下:
window.isIE=navigator.appName.indexOf("Microsoft")==0;
if(isIE){
document.documentElement.addBehavior("#default#userdata");
document.execCommand("BackgroundImageCache",false,true);
}
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?
/**
* 相關(guān)回復(fù)
* by Nicholas C. Zakas @2007-02-26
*/
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".
相關(guān)文章
js實(shí)現(xiàn)根據(jù)文件url批量壓縮下載成zip包
本文主要介紹了js實(shí)現(xiàn)根據(jù)文件url批量壓縮下載成zip包,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02JavaScript在IE和Firefox瀏覽器下的7個(gè)差異兼容寫法小結(jié)
盡管那需要用長(zhǎng)串的、沉悶的不同分支代碼來應(yīng)付不同瀏覽器的日子已經(jīng)過去,偶爾還是有必要做一些簡(jiǎn)單的區(qū)分和目標(biāo)檢測(cè)來確保某塊代碼能在用戶的機(jī)器上正常運(yùn)行。2010-06-06Js-$.extend擴(kuò)展方法使方法參數(shù)更靈活
在JS里,我們的方法參數(shù)通常使用JQ的$.extend擴(kuò)展方法來實(shí)現(xiàn),感興趣的朋友可以了解下2013-01-01給應(yīng)用部分的js代碼設(shè)定一個(gè)統(tǒng)一的入口
javascript是種腳本語言,瀏覽器下載到哪兒就會(huì)執(zhí)行到哪兒,下面為大家介紹下,如何給應(yīng)用部分的js代碼一個(gè)統(tǒng)一的入口2014-06-06JS onmousemove鼠標(biāo)移動(dòng)坐標(biāo)接龍DIV效果實(shí)例
這篇文章主要介紹了JS onmousemove鼠標(biāo)移動(dòng)坐標(biāo)接龍DIV效果實(shí)例,有需要的朋友可以參考一下2013-12-12原生js實(shí)現(xiàn)移動(dòng)端瀑布流式代碼示例
這篇文章主要為大家分享了原生js實(shí)現(xiàn)移動(dòng)端瀑布流式代碼示例,對(duì)瀑布流布局感興趣的小伙伴們可以參考一下2015-12-12JS高級(jí)運(yùn)動(dòng)實(shí)例分析
這篇文章主要介紹了JS高級(jí)運(yùn)動(dòng),結(jié)合實(shí)例形式分析了javascript運(yùn)動(dòng)框架原理、實(shí)現(xiàn)與應(yīng)用技巧,需要的朋友可以參考下2016-12-12