angularjs IE缓存拦截器有效,但破坏了指令

angularjs IE Cache buster works, but breaks directive

本文关键字:坏了 指令 有效 IE 缓存 angularjs      更新时间:2023-09-26

我在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

没有用于缓存的棱角分明的snippit,它工作得很好。。

希望你能帮忙!

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

兰登评论中的第一个解决方案

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

$httpProvider.defaults.headers.get['Cache-Control']="无缓存";$httpProvider.defaults.headers.get['Pagma']="无缓存";

lopisan 评论的第二个解决方案

If Modified Since="0"标头的使用破坏了Tomcat(问题具有解析标头日期,因为0不是有效值RFC)。固定使用值"Mon,Jul 26 GMT 05:00:00"。