避免angularJS在IE缓存局部视图 [英] Avoid angularJS partial views to be cached in IE

查看:159
本文介绍了避免angularJS在IE缓存局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个ASP.NET MVC应用程序,也有一些angularJS。我有了不同的选项卡,当你点击他们,他们装载的角度局部视图一个主页。这是主要的页面的样子:

I'm working on an ASP.NET MVC application that also has some angularJS. I have a main page that has different tabs that when you click them they load an angular partial view. This is how the main page looks like:

{ ... }     
<div class="widget-div" ng-controller="mainController"> 
    <div class="widget-body">
        <div class="tabs-left">
            <ul id="demo-pill-nav" class="nav nav-tabs tabs-left" style="width: 160px">
                <li ng-class="getMenuClass('/search')">
                    <a href="javascript:void(0);" ng-click="selectPage('search')">Search</a>
                </li>
                <li ng-class="getMenuClass('/addressVerification')">
                    <a href="javascript:void(0);" ng-click="selectPage('addressVerification')">Address Verification</a>
                </li>
                <li ng-class="getMenuClass('/dashboard')">
                    <a href="javascript:void(0);" ng-click="selectPage('dashboard')">Dashboard</a>
                </li>
                <li ng-class="getMenuClass('/editProfile')">
                    <a href="javascript:void(0);" ng-click="selectPage('editProfile')">Update Profile</a>
                </li>               
            </ul>
            <div class="tab-content">
                <div class="active tab-pane">
                    <ng:view />
                </div>
            </div>
        </div>
    </div>  
</div>
{ ... } 

在主控制器时,请选择数据的方法如下:

In the main controller, the selectPage method looks like:

$scope.selectPage = function (page) {
    //not relevant code removed here
    $location.path("/" + page);
};

当然,我已经定义喜欢的路线:

And of course I have defined the routes like:

$routeProvider.when("/search", {
    templateUrl: "/Scripts/app/views/search.html"
});

现在,我需要的是这些局部意见没有得到缓存,至少同时发展。对于我这里使用的方法提供

Now, what I need is these partial views to not get cached, at least while in development. For that I used the method provided here:

myApp.run(function($rootScope, $templateCache) {
   $rootScope.$on('$viewContentLoaded', function() {
      $templateCache.removeAll();
   });
});

这除了在Internet Explorer中,按Ctrl + F5键时,它总是也会加载缓存版本的工作完美。

That worked perfect except in Internet Explorer, which always will load the cached version even when hitting Ctrl+F5.

另外,我试图在布局HTML设置HTTP头,像这样的:

Also, I tried setting the HTTP headers in the layout html, like this:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />

但是,这并不能正常工作。

But that didn't work.

所以我的问题是,如果有什么办法避免这种行为。

So my question is if there is any way to avoid this behavior.

推荐答案

我发现了一个解决办法,这正是我需要的。添加一个版本号这样的路线:

I found a workaround that is exactly what I need. Adding a version number to the route like this:

$routeProvider.when("/search", {
    templateUrl: "/Scripts/app/views/search.html" + version
});

其中version是一个字符串,如:<?code> V1.0.0

这样,任何时候,我做出改变我只是改变了版本号和击中该页面的局部视图时,将重新下载。

That way any time I make a change I just change the version number and when hitting that page the partial view will be downloaded again.

这篇关于避免angularJS在IE缓存局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆