最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

關(guān)于angularJs清除瀏覽器緩存的方法

 更新時間:2017年11月28日 11:31:27   作者:狼牙冷  
這篇文章主要介紹了關(guān)于angularJs清除瀏覽器緩存的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

緩存篇

一個緩存就是一個組件,它可以透明地儲存數(shù)據(jù),以便以后可以更快地服務(wù)于請求。多次重復(fù)地獲取資源可能會導(dǎo)致數(shù)據(jù)重復(fù),消耗時間。因此緩存適用于變化性不大的一些數(shù)據(jù),緩存能夠服務(wù)的請求越多,整體系統(tǒng)性能就能提升越多。

瀏覽器緩存,有時候我們需要他,因為他可以提高網(wǎng)站性能和瀏覽器速度,提高網(wǎng)站性能。但是有時候我們又不得不清除緩存,因為緩存可能誤事,出現(xiàn)一些錯誤的數(shù)據(jù)。像股票類網(wǎng)站實時更新等,這樣的網(wǎng)站是不要緩存的,像有的網(wǎng)站很少更新,有緩存還是比較好的。

以下是傳統(tǒng)的清除瀏覽器的方法

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 
 }); 

用隨機數(shù),隨機數(shù)也是避免緩存的一種很不錯的方法!

URL 參數(shù)后加上 "?ran=" + Math.random(); //當(dāng)然這里參數(shù) ran可以任意取了 

用隨機時間,和隨機數(shù)一樣。

在 URL 參數(shù)后加上 "?timestamp=" + new Date().getTime();  

用php后端清理

在服務(wù)端加 header("Cache-Control: no-cache, must-revalidate");等等(如php中) 

下面介紹關(guān)于angularJs項目中清除瀏覽器的方法,當(dāng)然以上傳統(tǒng)的方法也是可以適用的,但對于angularJs來說還需添加以下幾項:

一、清除模板緩存

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

二、html添加隨機參數(shù)

.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'; 

好了……就這么多了

如果還有其他方法歡迎指點迷津!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

巧家县| 南澳县| 武山县| 梁平县| 南投县| 宽城| 五莲县| 四川省| 延安市| 沛县| 洞头县| 湾仔区| 阿坝县| 麻阳| 南木林县| 长宁区| 玉山县| 集安市| 阿拉善左旗| 平顺县| 蒲城县| 无锡市| 汽车| 广汉市| 文成县| 正宁县| 海原县| 乌拉特前旗| 涞源县| 西华县| 集贤县| 罗平县| 佛教| 买车| 天长市| 固镇县| 读书| 福清市| 寻乌县| 易门县| 贵州省|