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?