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?
Asked
Active
Viewed 1,756 times
0

tuhindas
- 11
- 4
-
You can append the upload timestamp to the image url – Anthony C Mar 24 '22 at 21:03
1 Answers
2
you have to implement a hash mechanism on your backend to add a hash string to the image name not on the client side

KeyvanKh
- 311
- 1
- 6
-
I use the updatedAt on the backend for this as extra query-param after the image url – Barna Burom Mar 23 '23 at 12:00