'Avoid image caching in browser in React
I have a code where the user's avatar is fetched from the backend. Now, the avatar file name is the same every time, even if a user uploads a new one because the backend replaces the old avatar with the new one with the same name. Since this was causing caching issue on the browser, I used [IMAGE_URL]?random={new Date().getSeconds()} to update the state immediately when user changes it. But this causes the avatar to download multiple times when the page loads or when a React state updates. Is there a way so that the image is not cached and also I don't have to put some random query strings?
Solution 1:[1]
you have to implement a hash mechanism on your backend to add a hash string to the image name not on the client side
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KeyvanKh |
