Search code examples
javascripthtmlangularcachingreload

How to do Empty Cache and Hard Reload from js in Angular?


When I publish updates of my application I wish to be sure that all files .js, .png and so on will be downloaded with status 200, not 304.

I tried to use this method:

window.location.reload(true);

But after it one can see that some files are still downloaded with 304 status.

How to do Empty Cache and Hard Reload from js in Angular to force all files be downloaded with 304 status?


Solution

  • You can force a reload by using output-hashing when creating a Production build see the documentation https://angular.io/cli/build. The documentaion states it as:

    Define the output filename cache-busting hashing mode.

    If you set it to all, a unique hash is added to the genrated build files, forcing a client browser to reload the files from the http server.