Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

798
Visualizações
How to force reload and clear cache in Typescript?

it recently came to my attention that simply using window.location.reload() is not a hard refresh i.e. cache is cleared along with the refresh. I was then told to use window.location.reload(true) but I discovered this has since been deprecated.

I am not sure how to determine whether or not the cache has been cleared, so I feel that any method that refreshes the page simply won't cut it for what I need to do, as I cannot tell if cache is being cleared.

I have seen various other approaches including window.location.href = window.location.href; but have seen comments saying this does not clear cache.

I have seen people say that using a "POST" method should do the trick, but I am not sure how to implement this into my current code. I am using a MatSnackBar to prompt the user to refresh the page when a newer version of the app has been released. Here is the code for that SnackBar:

showSnackbar(versionFromHTTP: string, appVersion: string): void {
   const httpList = versionFromHTTP.split('.');
   const appList = appVersion.split('.');
   if ((httpList[0] === appList[0]) && (httpList[1] === appList[1])){
     let snack = this.snackBar.open('We\'ve made new updates! Please refresh your browser to get the latest updates.', 'Refresh now');
     snack.onAction().subscribe(() => {
      window.location.href = window.location.href;
    });
   }
   else{
     let snack = this.snackBar.open('We\'ve made new updates - some features may not work correctly until you refresh your browser.', 'Refresh now');
     snack.onAction().subscribe(() => {
      window.location.href = window.location.href;
    });
    }
 }

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda