【问题标题】:angularjs IE Cache buster works, but breaks directiveangularjs IE Cache buster 可以工作,但是会破坏指令
【发布时间】:2014-10-23 05:18:37
【问题描述】:

我遇到了 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

没有用于缓存的角度片段,它可以正常工作..

希望你能帮忙!

【问题讨论】:

  • 你是什么意思“不能”,你得到一个错误?它提出请求吗?请注意,IE 没有console,除非您确实打开了控制台,否则可能会导致它中断。
  • 哦,对不起。生病添加错误。我的坏
  • 尝试添加这些标题:$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
  • 嗯,它似乎工作。但我不得不删除 $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';

标签: javascript angularjs internet-explorer caching


【解决方案1】:

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

commentLangdon 中的第一个解决方案

If-Modified-Since 标头使 IIS+iisnode 抛出 400 Bad Request 对于通过 ngInclude 和 ngView 加载的每个 html 文件。下列 不过,两个标题为我解决了这个问题(我从 Chrome 中提取了它们, 没有缓存问题):

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

commentlopisan 中的第二个解决方案

If-Modified-Since = "0" header 的使用破坏了Tomcat(问题 使用解析标头日期,因为 0 不是有效值 RFC)。固定使用 值“1997 年 7 月 26 日星期一 05:00:00 GMT”。

【讨论】:

  • 这两个建议都导致 Angular 抛出错误,并且我的网页无法正确呈现(我仍然会在页面上看到大括号,而不是 Angular 绑定的值..)
猜你喜欢
  • 1970-01-01
  • 2016-03-25
  • 2010-10-31
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-09
相关资源
最近更新 更多