javascript - angularjs IE Cache buster 可以工作,但会破坏指令

标签 javascript angularjs internet-explorer caching

我在 IE 缓存所有内容时遇到问题,所以如果我切换用户,我仍然会看到来自不再登录的旧用户的数据。

我试过这个解决方案(位于:Angular IE Caching issue for $http),它有效但现在我的指令无法获取它需要的模板,我怎样才能让这两个都起作用?

代码:

   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';
}]);

我的指令:

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

编辑! 无论使用哪种浏览器,它都会出错,这是来自 chrome 的:

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

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

没有用于缓存的 Angular snippit,它工作正常..

希望你能帮上忙!

最佳答案

在您提供的资源中,有两个可能的修复方法。

第一个解决方案 comment通过 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';

comment 中的第二个解决方案通过 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.

关于javascript - angularjs IE Cache buster 可以工作,但会破坏指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25564139/

相关文章:

javascript - Casperjs Google 登录 (V2) 无法正常工作

javascript - 尝试从 HTML 表单获取值?

javascript - 检查数组中是否存在该属性

javascript - 如何在 AngularJS Controller 中执行 if 语句

html - 在IE9中,伪元素:after on a TD doesn't get the correct TD height,有解决办法吗?

javascript - 带有样式的 IE 新元素?

javascript - Grails - 在 javascript 中访问 http 数据

javascript - 使用用户定义的 SVG 多边形

javascript - 模拟 angularjs http 请求

php - IE 和空白