0

For some reason, chrome keeps loading index.html from cache. In network tab of developers tool, I get 200 Ok (loaded from disk cache). When I disable cache or clear cache, then it loads fresh copy of index.html. But the issue doesn't happen in other browsers (e.g. edge).What am I doing wrong? How do I force chrome not to use cache at all and always fetch fresh copy just like it would when I hit F5? Here's my html.

<head>
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Expires" content="0"/>
<meta http-equiv="Pragma" content="no-cache"/>
</head>
prabhat
  • 87
  • 1
  • 1
  • 10
  • I have tried putting just content="no-store" for cache-control. No luck – prabhat May 01 '19 at 01:32
  • Write a http interceptor and before your get the service call `window.location.reload(true);` it will remove the cache and reload the page. – Sourav Dutta May 01 '19 at 04:03
  • For obvious reasons, location.reload(), refreshes the page, Also check this post there are [few ways](https://stackoverflow.com/questions/34808023/how-to-clear-template-cache), might be helpful ! – Sourav Dutta May 01 '19 at 04:09

1 Answers1

0

Open the developer toolbar by ctrl + shift + I.

Goto Application -> clear storage. Click on Clear site data(Tick all checkbox).

This is happening because of the service worker

Omkar Yadav
  • 523
  • 1
  • 6
  • 14
  • Thanks Omkar. Yes it works when i clear the cache as you said. But, I need to fix it in application code so that user doesn’t have to perform clear cache. Can you please explain about service worker? – prabhat May 01 '19 at 16:59
  • @Praati enable service worker when it is production env. `ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })` Read more at: https://angular.io/guide/service-worker-getting-started – Omkar Yadav May 02 '19 at 07:52