javascriptangularauto-updateclear-cache

How to update our website to latest version using JavaScript ? Basically Hard Reload or Clear cache and reload


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.


Solution

  • 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 🙏