How to force a web browser NOT to cache images

后端 未结 17 979
太阳男子
太阳男子 2020-11-22 13:51

Background

I am writing and using a very simple CGI-based (Perl) content management tool for two pro-bono websites. It provides the website administrator with HTML

17条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 14:31

    From my point of view, disable images caching is a bad idea. At all.

    The root problem here is - how to force browser to update image, when it has been updated on a server side.

    Again, from my personal point of view, the best solution is to disable direct access to images. Instead access images via server-side filter/servlet/other similar tools/services.

    In my case it's a rest service, that returns image and attaches ETag in response. The service keeps hash of all files, if file is changed, hash is updated. It works perfectly in all modern browsers. Yes, it takes time to implement it, but it is worth it.

    The only exception - are favicons. For some reasons, it does not work. I could not force browser to update its cache from server side. ETags, Cache Control, Expires, Pragma headers, nothing helped.

    In this case, adding some random/version parameter into url, it seems, is the only solution.

提交回复
热议问题