您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 烟台分类信息网,免费分类信息发布

在angularJs中如何实现清除浏览器缓存

2024/5/14 15:02:28发布42次查看
这篇文章主要介绍了关于angularjs清除浏览器缓存的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
缓存篇
一个缓存就是一个组件,它可以透明地储存数据,以便以后可以更快地服务于请求。多次重复地获取资源可能会导致数据重复,消耗时间。因此缓存适用于变化性不大的一些数据,缓存能够服务的请求越多,整体系统性能就能提升越多。
浏览器缓存,有时候我们需要他,因为他可以提高网站性能和浏览器速度,提高网站性能。但是有时候我们又不得不清除缓存,因为缓存可能误事,出现一些错误的数据。像股票类网站实时更新等,这样的网站是不要缓存的,像有的网站很少更新,有缓存还是比较好的。
以下是传统的清除浏览器的方法
meta方法
//不缓存 <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache, must-revalidate"> <meta http-equiv="expires" content="0">
清理form的临时缓存
<body onload="javascript:document.yourformname.reset()">
ajax清除缓存
$.ajax({ url:'www.haorooms.com', datatype:'json', data:{}, cache:false, ifmodified :true , success:function(response){ //操作 } async:false });
用随机数,随机数也是避免缓存的一种很不错的方法!
url 参数后加上 "?ran=" + math.random(); //当然这里参数 ran可以任意取了
用随机时间,和随机数一样。
在 url 参数后加上 "?timestamp=" + new date().gettime();
用php后端清理
在服务端加 header("cache-control: no-cache, must-revalidate");等等(如php中)
下面介绍关于angularjs项目中清除浏览器的方法,当然以上传统的方法也是可以适用的,但对于angularjs来说还需添加以下几项:
一、清除模板缓存
.run(function($rootscope, $templatecache) { $rootscope.$on('$routechangestart', function(event, next, current) { if (typeof(current) !== 'undefined'){ $templatecache.remove(current.templateurl); } }); });
二、html添加随机参数
.state("content", { url: "/", views:{ "bodyinfo":{templateurl: 'tpls/bodyinfo.html?'+ +new date(), controller:'bodyinfoctrl'}, "header":{templateurl: 'tpls/header.html?'+ +new date(), controller:'headerctrl' }, "footer":{templateurl: 'tpls/footer.html?'+ +new date(), controller:'footerctrl' } } })
<link rel="stylesheet" href="stylesheets/main.css?version=1.0.3" rel="external nofollow" >
三、清除route缓存
.config(['$stateprovider', '$urlrouterprovider','$locationprovider','$httpprovider',function($stateprovider, $urlrouterprovider,$locationprovider,$httpprovider) { // $urlrouterprovider.when("", "/home"); $urlrouterprovider.otherwise('/'); if (!$httpprovider.defaults.headers.get) { $httpprovider.defaults.headers.get = {}; } $httpprovider.defaults.headers.common["x-requested-with"] = 'xmlhttprequest'; $httpprovider.defaults.headers.get['cache-control'] = 'no-cache'; $httpprovider.defaults.headers.get['pragma'] = 'no-cache';
好了……就这么多了
如果还有其他方法欢迎指点迷津!
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
在vue.js中如何实现组件间循环引用
在vue中有关于异步组件的示例
在nodejs中如何解决超出最大的调用栈错误
在vue+springboot中如何实现博客管理平台
以上就是在angularjs中如何实现清除浏览器缓存的详细内容。
烟台分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录