AngularJS caching issue for Internet Explorer

Posted By : Ashish Sharma | 05-Feb-2014

AngularJS Caching

When we use $http to get the data from the server in AngularJS a small issue arises only in Internet Explorer. The major problem of this issue is that if we want to refresh the data by sending the same call again to the server, Internet Explorer fetches the data from the cache and do not show the updated result.

To solve the problem you only have to implement a small code in your AngularJs Module Configuration part

var myApp = angular.module('myApp', ['ngRoute']);

myApp.config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
    $httpProvider.defaults.cache = false;
    if (!$httpProvider.defaults.headers.get) {
      $httpProvider.defaults.headers.get = {};
    }
    // disable IE ajax request caching
    $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
	//.....here proceed with your routes
}]);

About Author

Author Image
Ashish Sharma

Ashish is a bright Groovy and Grails developer and have worked on development of various SaaS applications using Grails technologies. Ashish likes PC games and works out at Gym in his free time.

Request for Proposal

Name is required

Comment is required

Sending message..