how to clear or replace a cached image

后端 未结 20 1575
囚心锁ツ
囚心锁ツ 2020-11-29 02:04

I know there are many ways to prevent image caching (such as via META tags), as well as a few nice tricks to ensure that the current version of an image is shown with every

20条回答
  •  执笔经年
    2020-11-29 02:29

    In the event that an image is re-uploaded, is there a way to CLEAR or REPLACE the previously cached image client-side? In my example above, the goal is to make the browser forget what "42.jpg" is

    You're running firefox right?

    • Find the Tools Menu
    • Select Clear Private Data
    • Untick all the checkboxes except make sure Cache is Checked
    • Press OK

    :-)

    In all seriousness, I've never heard of such a thing existing, and I doubt there is an API for it. I can't imagine it'd be a good idea on part of browser developers to let you go poking around in their cache, and there's no motivation that I can see for them to ever implement such a feature.

    I CANNOT use the META tag method OR the timestamp method, because I want all of the images cached under normal circumstances.

    Why can't you use a timestamp (or etag, which amounts to the same thing)? Remember you should be using the timestamp of the image file itself, not just Time.Now.
    I hate to be the bearer of bad news, but you don't have any other options.

    If the images don't change, neither will the timestamp, so everything will be cached "under normal circumstances". If the images do change, they'll get a new timestamp (which they'll need to for caching reasons), but then that timestamp will remain valid forever until someone replaces the image again.

提交回复
热议问题