Home > Web Front-end > JS Tutorial > IE image cache document.execCommand('BackgroundImageCache',false,true)_javascript skills

IE image cache document.execCommand('BackgroundImageCache',false,true)_javascript skills

WBOY
Release: 2016-05-16 18:10:03
Original
1064 people have browsed it

The Pixy method is affected by IE's cache bug and will flicker. In fact, this problem is not clearly stated, but in fact the bug is conditional, that is, IE's cache is set to Every visit to the page, rather than the default Automatically. Basically, only developers will set the cache to check for updates every time they are accessed, so this bug will not actually affect real users (according to the test under winxpsp2 and ie6, although the network access api may still be called, but No actual request occurs. The symptom is that the mouse jitters for a very short time, but the image does not flicker). In addition, someone found an undisclosed method to let IE cache the background image: document.execCommand("BackgroundImageCache",false,true)
Using this method even avoids api calls, and it seems to be cached directly in IE memory. middle.

The background image set under IE6 will not be cached. Even if the server is cached, if you want to cache it, it can only be cached~~~

People who have done UI design and development must As you know, IE (excluding IE7) will often reload the background image from the server, and the good UI interface is being tossed in IE (excluding IE7)...

Erik discovered A simple solution (valid for IE below IE7, in fact, this bug has been fixed in IE7)

Program code

Copy code The code is as follows:

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

I found Jack while reading the source code of Ext today. Slocum has taken this into consideration and provided its implementation in Ext.js. There should be no such similar code in other Ajax frameworks. From this detail, we can see the comprehensiveness of Ext~

Program code
Copy code The code is as follows:

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){}
}

When I read the source code of Huanyu’s dreamplayer player today, I found that Huanyu Yu also repaired IE's background cache, but he didn't consider that this phenomenon no longer exists in IE7. This is a relevant code in evml.js~ (By the way, he muttered a few words: This guy never writes JS. Adding semicolons was like this before, and it is still like this now. How can we compress it like this? Ha~ The following code has been added with semicolons according to my habit, even if it is only two or three sentences~)

Program code
Copy code The code is as follows:

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?

/**
* Related replies
* 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".
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template