Dynamic Image Refresh Using Cachebreaker
When accessing a dynamic image source that provides a new image upon each load, it's crucial to force a refresh to display the updated image on the webpage.
The issue arises when loading the new image in the background and attempting to replace the existing one on the page. Despite the new image being loaded, it may not display until the page is refreshed.
To resolve this, a cachebreaker can be appended to the end of the image URL:
newImage.src = "http://localhost/image.jpg?" new Date().getTime();
This approach adds the current timestamp to the URL, instructing the browser to retrieve the image directly from the source rather than from its cache. Consequently, the browser will always fetch the latest version of the image, ensuring that the updated image is displayed on the page.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3