-5

I want to be able to refresh the page every time someone opens it.

I need this because I have a web app (PWA) and iOS caches the state and it doesn't communicate with the browser unless you delete data and cookies from your phone, which of course you cannot tell the user to do that.

I want to be able to refresh every time the page is opened. Is there a way to accomplish this?

I tried just putting window.location.reload(true) but this would only cause the page to load on a loop without being able to see the content once.

MCM
  • 141
  • 2
  • 15
  • Possible duplicate of [Detect If Browser Tab Has Focus](https://stackoverflow.com/questions/7389328/detect-if-browser-tab-has-focus) – rlemon Jul 03 '19 at 20:29
  • 1
    You can probably set the [Cache-Control](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control) and/or [Expires](https://developer.mozilla.org/docs/Web/HTTP/Headers/Expires) headers to control this. – Stephen P Jul 03 '19 at 20:39

2 Answers2

0
if(!window.location.hash.includes("#reloaded")) {
    window.location.href += "#reloaded";
    window.location.reload()
}

This will check if there is #reloaded in the URL and if not reload the page then add the #reloaded

Example

User hits http://example.com/link then the script checks if it has #reloaded in the URL and if not adds so it be http://example.com/link#reloaded.

Jamal Abo
  • 472
  • 4
  • 16
-2
$( document ).ready(function() {
    window.location.reload();
});