且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

清除Angular中的浏览器缓存

更新时间:2023-02-22 09:30:39

使用ng build构建应用程序时,应使用以下标志:

When you are building the application using ng build, you should use the following flag:

--outputHashing=all

这是为了启用缓存清除.这样会将哈希添加到每个生成的文件中,这样,每当您将新版本上载到服务器时,浏览器都将***加载最新版本.

This is to enable cache-busting. This adds a hash to every single built file such that the browser is forced to load the latest version whenever you have uploaded a new version to your servers.

因此,一种方法是运行以下代码:

Threfore, one way to do it would be to run this:

ng build --prod --outputHashing=all

您可以在此处上阅读有关构建选项标志的更多信息.

You may read more about the build options flags over here.

如果您不希望在运行ng build时附加标志,则应在您的配置文件中的angular.json文件中进行设置.

If you do not wish to append the flags when you run ng build, you should set it on your configurations at the angular.json file.

"configurations": {
  "production": {
    "optimization": true,
    "outputHashing": "all",
     .
     .
     .
  }
}