Web page through JS modified img src attribute refresh picture, picture caching problem phenomenon expression and problem solving __js
Source: Internet
Author: User
Question: Upload a picture, through JS update src property Refresh the picture so that it immediately displayed,
When the current URL of the IMG src is unchanged from the last address (only change the picture, the name does not change, different picture names are the same) the picture does not change (still shows the original picture)
But the picture has changed through Firebug, because when the SRC address is unchanged, the browser will not reload the picture still read from the cache
Method: You can only change the content of SRC address every time you refresh the picture,
(1) Through the foreground change, let JS generate a random number for each parameter placed behind the URL, but this parameter has no practical significance
(2) Each request to the picture page, from the background to pass a random number, the foreground to obtain the random variable and placed behind the URL, the random number also has no practical significance
Principle:
Because of the addition of random number parameters in the IMG src, multiple access to the image, the browser is considered to have access to a different picture path (or access to a different picture),
The browser reads the picture every time it accesses the server, and no longer reads the picture in the cache.
Example: $ ("#empImgContent"). attr (' src ', src= "**/uploads/empimgs/" + empobj.emppic+ "t=" + math.random ()); Show pictures
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.