代码之家  ›  专栏  ›  技术社区  ›  Kevin Quiring

(Angular 4,AOT,缓存刷新)当服务器上发生代码更改时,如何强制最终用户浏览器进行硬刷新?

  •  3
  • Kevin Quiring  · 技术社区  · 7 年前

    我读过关于在后面添加版本号的内容。css和。js文件,因此浏览器重新下载新命名的文件,但使用角度AOT创建ngfactory。js文件和ngfactory。js。地图文件等,我想确保我这样做是正确的。

    2 回复  |  直到 7 年前
        1
  •  0
  •   ttugates    7 年前

    当您使用 ng build --prod 这也意味着aot,生成的bundle有了新的名称。。

    一种常见的方法是将IIS配置为从不允许缓存索引。html。。这样,如果客户端在始终当前的索引中看到相同的捆绑名称。html,其缓存。。但是如果你生成了一个新的包,它就会被下载。

    相关SO答案 here .

        2
  •  0
  •   CodeMind    5 年前

    为此,您可以将iis设置为不缓存索引。html文件。为此,您必须简单地包括web。配置文件并将此设置添加到其中。

    <configuration>
    
      <location path="index.html">
        <system.webServer>
          <httpProtocol>
            <customHeaders>
              <add name="Cache-Control" value="no-cache" />
            </customHeaders>
          </httpProtocol>
        </system.webServer>
      </location>
    
    </configuration>