gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:33:15 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com