我在 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,它工作正常..
希望你能帮上忙!
最佳答案
在您提供的资源中,有两个可能的修复方法。
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';
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/