Angular应用总是使用缓存版本,不需要手动硬刷新



我已经把Angular 7应用部署到Azure应用服务中了。在每次新部署之后,即使我启动了一个新浏览器,我也必须手动刷新或硬刷新浏览器页面才能看到新的更改。

我可以看到在我的部署中,index.html文件每次都嵌入了新的散列文件名。

<script type="text/javascript" src="runtime.5959ec9531e22bc6ae82.js"></script>
<script type="text/javascript" src="es2015-polyfills.d9df4d9cef7e9c40c764.js" nomodule></script>
<script type="text/javascript" src="polyfills.eb0596823492af2b4693.js"></script>
<script type="text/javascript" src="main.1eb70d066995e0724818.js"></script>

为什么应用程序没有自动重新加载index.html ?如何解决这个问题?

生成的index.html被缓存.

我建议仅为location/index.html文件禁用缓存,因此浏览器总是至少加载index.html。

因为生成的css和js在文件名中包含一个哈希值,如果生成的文件在构建后更改,则该哈希值会更改,因此用户应该始终获得最新版本。

最新更新