Pages

Thursday, June 20, 2013

How to stop some images loading from chache

In some cases we need to stop loading resources from cache. Say for an example, when we need to update a profile picture, we should not allow the cache to load the image again. So how are we going to do this. You can achieve this in two different ways.

  1. Add a parameter to the end of the url. Eg: http://your.site.com?random=98798987987 Important thing to notice here is you need to add a random variable in order to make the url different from the previous one
  2. The other method is to configure the headers in the request . But the downside of this approach is, You will need to set different headers parameters based on different browsers. eg. header("Pragma-directive: no-cache"); header("Cache-directive: no-cache"); header("Cache-control: no-cache"); header("Pragma: no-cache");  header("Expires: 0")

No comments:

Post a Comment