angularjs怎么清除在ie下的缓存

angularjs怎么清除在ie下的缓存

阅读 4k
4 个回答

ctrl+f5强制清除缓存刷新

如果是简单的清楚IE缓存,你可以自行百度如何清楚IE缓存。
默认你的问题是开发过程中重复测试因为缓存问题刷新不出来,我的做法是在路径上加上时间戳
图片描述

这是我自己从网上找来的代码,自己也在用(兼容ie8+)。以下代码放在config 中即可,主要是用于防止ie 浏览器缓存 get 请求,希望能帮到你。

            // Initialize get if not there
            if (!$httpProvider.defaults.headers.get) {
                $httpProvider.defaults.headers.get = {};
            }

            // Enables Request.IsAjaxRequest() in ASP.NET MVC
            $httpProvider.defaults.headers.common['X-Requested-With'] =
                'XMLHttpRequest';

            // Disable IE ajax request caching
            $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
            $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
            $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';

在你的路由文件的后面加上这句话就可以了
// 一般是angular.module('xxx').config(...)

// 禁止模板缓存
angular.module('xxx').run(['$rootScope', '$templateCache', function($rootScope, $templateCache) {

$rootScope.$on('$routeChangeStart', function(event, next, current) {  
    if (typeof(current) !== 'undefined'){  
        $templateCache.remove(current.templateUrl);  
    }  
});  

}]);

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题