Next.js Discord

Discord Forum

Disable cache for images

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
At my website a user can have a profile pic. Obviously the user can update this picture at any time by accessing the profile settings. I want to disable cache for this image because when the user updates it, takes too many time and too many page reloads to actually see the updated picture. How can I do that?

1 Reply

@Asian black bear At my website a user can have a profile pic. Obviously the user can update this picture at any time by accessing the profile settings. I want to disable cache for this image because when the user updates it, takes too many time and too many page reloads to actually see the updated picture. How can I do that?
I think you could do that by passing unoptimized to <Image /> but it will turn off optimization for that image.

Are you using the same name of the profile picture?
Maybe try adding random string to the name of the profile pic and re-generate it on every update like this eg.
const filename = `profile-${crypto.randomUUID()}.png`

then it should create a new cache on every change so you could keep image optimization