Tell the browser to drop cache of image

拟墨画扇 提交于 2019-12-25 08:48:12

问题


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?


回答1:


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

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




回答2:


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.



来源:https://stackoverflow.com/questions/40358839/tell-the-browser-to-drop-cache-of-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!