0

Is there a reliable way to stop all browsers from caching an image locally. This is not (just) about the freshness of the image, but rather a concern about sensitive images being stored on the local drive. Adding a random url param to the img url as suggested in similar questions does not help because that just ensures the next request is not the last request in cache (at least that is my understanding). What I really need is for the image to never be saved locally or at least not accessible outside the browser session if it is saved.

user2245759
  • 477
  • 6
  • 17

1 Answers1

0

You need to send appropriate cache-control headers when serving up the response for image request. See this post for information on standard ways to do this in several programming languages.

How to control web page caching, across all browsers?

There is an alternate, and possibly more foolproof yet more complex, approach which would be to directly populate base 64 encoded images data directly into the img src attrbitute. So far as I know this would not be subject to caching, as there is not a separate HTTP request made to retrieve the image. Of course you still need to make sure the page is not cached, which gets back to the initial problem of serving up appropriate headers for primary HTML request.

Community
  • 1
  • 1
Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • Thanks. I've seen/ often used the headers approach but didn't know if that included the images on the page as well or is it just the page as a whole. Also I had seen other references to these header tags with commenters saying "didn't work for me" and the like so i was wondering how bullet proof it was. – user2245759 Dec 05 '14 at 21:13
  • @user2245759 I don't know that this could be considered "bulletproof", but the reality is that I don't know if you are going to find something that is going to be 100% effective across all browsers. – Mike Brant Dec 05 '14 at 21:18
  • @user2245759 Added some additional thoughts on using base 64 encoded image data directly in page, which you might find to be an option to pursue. – Mike Brant Dec 05 '14 at 21:21