Is it really useful to preload a picture with new image ()? _ Image Effects

Source: Internet
Author: User
Tags html page
It is often used to alternately display pictures on a Web page. A lot of the recommended practice is to use new image () to mount the picture beforehand. But is it really useful to use new Image ()?
Test:
Place a filter in the background to capture all/* requests:
Dofilter the URL of a simple print request:

Code
HttpServletRequest HttpRequest = (httpservletrequest) request;
System.out.println ("Requets URL:" + Httprequest.getrequesturi ());
Chain.dofilter (request, response);

HTML code:
Code
<body> <script> var t1 = new Image (); T1.SRC = ' ico_unchecked.gif '; function Change () {im.src = T1.SRC; } </script> <button onclick= "Change ()" >change</button> </body>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

You can see that the URL was printed three times. The request for an HTML page is once. T1.SRC set the value once. Time once.
I think this time if you press the button to change the picture on the page, you should no longer download the picture from the service, because the cache already have. But the point of time the filter is still there to print out url!
It appears that as long as the src of the image object is changed, a request will be made. is the pre-loading picture not equal to useless?

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.