且构网

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

清除 Angular 中的浏览器缓存

更新时间:2023-02-22 09:34: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",
     .
     .
     .
  }
}