简体   繁体   中英

After modifcating an “img.png”, the img src='img.png' tag continues getting the older “img.png”

I have an image "img.png" with content 'A', the user changes the content of this img to 'B'. All via Ajax. When I try to put this "img.png" in some img src tag it shows me the 'A' content instead of the 'B', but when I reload the page, he shows me the 'B' correctly. OBS:Obviously that is a simplified and summed up case, but some very similar is happening to me. Please help.

As the images are "re-using" the same URL, your logic should also append a query string with a versioning number or timestamp to the image URL. Also simplified:

timestamp = Date.now();

img.src = sitename="/image.png?"+ timestamp;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM