2

I have had a problem with IE caching everything, so if i switched user, i would still see data from the old user which is not logged in anymore.

I tried this solution (found at : Angular IE Caching issue for $http ), and it worked but now my directive can't GET the template it needs, how can i get both things to work ?

code:

   app.config(['$httpProvider', function ($httpProvider) {
    //initialize get if not there
    if (!$httpProvider.defaults.headers.get) {
        $httpProvider.defaults.headers.get = {};
    }
    console.log($httpProvider.defaults.headers.get['If-Modified-Since']);

    //disable IE ajax request caching
    $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
}]);

My directive:

app.directive('commentsContainer', function (commentResource, signalRService) {
return {
    restrict: 'EAC',
    templateUrl: '/Templates/Directives/_Comments.html',
    link: function ($scope) {
         //CODE
    }
}

EDIT! it get an error no matter which browser, here is the one from chrome :

GET http://localhost:58991/Templates/Directives/_Comments.html 400 (Bad Request) 

Error: [$compile:tpload] Failed to load template: /Templates/Directives/_Comments.html

Without the angular snippit for caching, it works fine..

Hope you can help!

Community
  • 1
  • 1
Ngschumacher
  • 140
  • 1
  • 10

1 Answers1

1

In the resource you provided there is two possible fixes.

First solution in comment by Langdon

The If-Modified-Since header makes IIS+iisnode throw 400 Bad Request for every html file loaded through ngInclude and ngView. The following two headers fixed the issue for me though (I pulled them from Chrome, which didn't have the caching issue):

$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

Second solution in comment by lopisan

The usage of If-Modified-Since = "0" header breaks Tomcat (Problem with parsing header date, as 0 is not valid value RFC). Fixed using value 'Mon, 26 Jul 1997 05:00:00 GMT' instead.

Community
  • 1
  • 1
Nicklas Kevin Frank
  • 6,079
  • 4
  • 38
  • 63
  • Both suggestions caused Angular to throw an error, and my webpage to not render properly (I'd still see curly brackets on the page, rather than Angular-binded values..) – Mike Gledhill Aug 18 '15 at 07:59