1

I have deployed the latest version of my website, but until I do Clear cache and reload, My website is not updating automatically. How can I do this in the code using JavaScript? Thanks in advance.

I have tried using

  1. window.location.reload()
  2. location.reload()
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />

But nothing were working as expected.

SrArkaitz
  • 488
  • 2
  • 8
  • 20
  • 2
    Is it a PWA? In that case all your files are cached by the serviceWorker. You need to increment the `"version"` in `ngsw-config.json`, and call [`SwUpdate`](https://github.com/MintPlayer/MintPlayer/blob/master/MintPlayer.Web/ClientApp/src/app/app.component.ts#L87) from code. Obviously you'll still need a hard reload to get this new version, but then you should be fine – Pieterjan Jan 03 '23 at 07:13
  • Have you tried using the --output-hashing=all flag when building ? More on this [here](https://stackoverflow.com/questions/55402751/angular-app-has-to-clear-cache-after-new-deployment/55403095#55403095) – Tommi Jan 03 '23 at 09:08

1 Answers1

1

In my Angular application, I had the same issue.

My solution was to clear the cache memory and also update the HTML page content.

Here is an example:

setTimeout(() => {
            const content = await 
            window.fetch(location.host).then(response =>{ 
            htmlContent = response.text();
            location.reload(true)})
}, 1000)

I hope this help

Efrat Ifergan
  • 184
  • 1
  • 5