It is often used to show images alternately on webpages. We recommend that you use new Image () to preload images. But is it useful to use new Image?
Test:
Put a filter in the background to capture all/* requests:
In doFilter, simply print the request URL:
Code
HttpServletRequest httpRequest = (HttpServletRequest) request;
System. out. println ("requets url:" + httpRequest. getRequestURI ());
Chain. doFilter (request, response );
Html code:
Code
<Body> <button onclick = "change ()"> change </button> </body>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Three URLs are printed. An html page is requested once. T1.src is set once. .
I think at this time, if you press the button to change the image on the page, the image will not be loaded from the server, because the cache already exists. However, the filter still prints the URL!
As long as the src of the image object is changed, a request is sent. Isn't pre-loading images useless?