Clear browser cache in Angular

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.

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",
     .
     .
     .
  }
}

Leave a Comment