1

我正在 AngularJs 中构建一个 Office Web 应用程序,并且我的视图正在被缓存,我正在尝试研究如何防止我的 AngularJS 视图被缓存。

更改 Index.html 文件,因为 *.js 反映在选项卡窗格中,但视图中的任何更改都不会。以下是一些没有奏效的事情:

将这些添加到 index.html 的标题中:

<meta http-equiv="cache-control" content="no-store">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">

将此添加到 application.js:

app.run(function ($rootScope, $templateCache) {
    $templateCache.removeAll();

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

将此添加到 web.config:

  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="DisableCache" />
    </staticContent>
  </system.webServer>

唯一有效的是重命名视图。

单独使用时,缓存不会出现在 Chrome、Firefox 甚至 IE 中。

4

1 回答 1

1

这可以通过 ng-include 标记中的简单查询字符串来解决,正如在一般使用查询字符串的 html 缓存的解释中所指出的(但在这种情况下也适用于 Angular)。

因此,在我的 Office 任务窗格应用程序中,我有一个ng-include="'partials/allhtml.html'"并将其更改为ng-include="'partials/allhtml.html?v=1.0.1'"并解决了我的缓存问题。

如链接中所述,您不需要每次都更改 ?v 的值;只要你有一个查询字符串,那么 http get 就不会被缓存!

于 2015-06-30T23:48:37.770 回答