php_nub_qq
php_nub_qq

Reputation: 16065

Tell the browser to drop cache of image

I have the common problem where when users change their profile picture it will not immediately appear on the web page, they will keep seeing the old one until the browser decides to drop the cached version.

The common solution for this problem is to add some unique query string so that the browser will not have it cached, like img.png?cache-breaker=rjqwrj0.

This causes another problem for me - it gets logged in the web server's access logs and when they are being parsed each request gets counted as a separate resource, where actually it is requesting the same resource with a different query string.

Is there any particular solution on the client side where I can tell the browser to explicitly drop the cache of the image that the user is about to upload, so it will get downloaded again when the page refreshes?

Upvotes: 0

Views: 99

Answers (2)

sabithpocker
sabithpocker

Reputation: 15576

May be you can version the profile pic file. Usual versioning like v=0.1 can expose the number of times user changed their pic, so it better to use a uuid. Every time user uploads a new image, change the uuid.

img.png?v=<some generated uuid>

This way you get a new URL per file change.

Upvotes: 0

felix91
felix91

Reputation: 462

<img src="img.png?lastmod=yourtimeinnumbers"...

it will give a cache option for img without dropping the browser cache

Upvotes: 2

Related Questions