Prevent GET request caching in Angular

Ran into an issue with Angular where it was caching GET requests in IE. I ended up modifying my application so that it appends no-cache headers for GET requests. This way I don't need to send modify each request or send additional values in the query string.

app.config(['$httpProvider',  
  function($httpProvider) {

    if(!$httpProvider.defaults.headers.get) {
      $httpProvider.defaults.headers.common = {};
    }          

    $httpProvider.defaults.headers.common["If-Modified-Since"] = "0";
    $httpProvider.defaults.headers.common["Cache-Control"] = "no-cache";     
    $httpProvider.defaults.headers.common.Pragma = "no-cache";                     
  }
]);

This seems to work pretty well, but if you have a better way, leave it in the comments!

comments powered by Disqus