IE6 BUG: IMG created with innerhtml in window. onload will ignore local cache

Source: Internet
Author: User

This problem occurs today. IE6 uses innerhtml to dynamically insert images in window. onload. As a result, these images ignore the local cache policy and send n more than 304 requests.

As a result, I used another method. Instead of using IMG in innerhtml, I used CSS styles in the newly added HTML Tag of innerhtml to Import images. However, the problem persists. IE6 still sent 304 requests.

I found an emu blog on the Internet and said that IMG created by innerhtml ignores the local cache. The sample code is as follows. Is it true that the IMG created by innerhtml ignores the cache? Not necessarily!

<HTML>
<Body>
<Div id = "DD"> </div>
</Body>

<SCRIPT type = "text/JavaScript">...
VaR A = new array (101 );
VaR S = " <br/> ";

Window. onload = function ()
...{
Document. getelementbyid ("DD"). innerhtml = A. Join (s );
}
</SCRIPT>
</Html>

When running the above Code, monitoring HTTP requests is indeed sending 304 requests, but in my mztreeview, I also used innerhtml to create a large number of and did not find that the local cache is invalid, the root cause is not in innerhtml, but in window. onload. Change the same code to the following code and try again:

 

<HTML>
<Body>
<Div id = "DD"> </div>
</Body>

<SCRIPT type = "text/JavaScript">...
VaR A = new array (101 );
VaR S = " <br/> ";
Document. getelementbyid ("DD"). innerhtml = A. Join (s );
</SCRIPT>
</Html>

 

Use the HTTP request monitoring software!

IE6 does have a dynamically created IMG bug that ignores local cache, but this bug is not in innerhtml but in window. onload. This bug has been fixed in IE7.

Bug fixes:
First, put the script in the back and run it directly as in the above example;
Second, use setTimeout to delay execution in window. onload.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.