5

This is one of those, "I need a workaround so as not to have to endure 1000 years of bickering from users, once the project launches" type questions:

I have a situation where I need to have my site reload any time someone launches Chrome without closing the tab last time they closed the browser. We are rebuilding an ancient site in a modern, MEAN stack environment, and I just know I will get complaints on this when it launches.

In other words (danger: psuedocode) -

if client closed chrome with site open
  reauthenticate user
  redirect to home page

I can accomplish the last two bits through an express route and passport auth, but how do I detect if the client is loading a cached page from their end?

Jensen010
  • 445
  • 6
  • 18
  • Possible duplicate of https://stackoverflow.com/questions/260043/how-can-i-use-javascript-to-detect-if-i-am-on-a-cached-page – Jay Aug 03 '18 at 17:20
  • Doesnt the same happen when you leave the tab and go back to it after some time? – Jonas Wilms Aug 03 '18 at 17:29
  • To clarify, I'm looking to reload the page ANY time it's opened from the client cache, as loading a cached page causes some 500 errors with our setup – Jensen010 Aug 03 '18 at 17:30
  • Is it possible to simply store some sort of js variable that is only set true after an actual login, or does Chrome keep that stored on close as well? – critical_error Aug 03 '18 at 17:45
  • @CriticalError In the authentication portion, hmm.....it's worth a shot – Jensen010 Aug 03 '18 at 17:48

1 Answers1

1

Is it possible to simply store some sort of js variable that is only set true after an actual login, or does Chrome keep that stored on close as well?

A simple example to go along with my comment:

<html>
<head>
    <script>

        function DoMagic() {
            document.getElementById( "magic" ).innerHTML = "<h1>Hello World!</h1>";
        }

    </script>
</head>
<body>

    <div id="magic">Waiting for magic</div>
    <br>
    <input type="button" value="Do Magic" onclick="DoMagic();" />

</body>
</html>
  • Open this in Chrome the div reads "Waiting for magic".
  • Click "Do Magic" div reads "Hello World".
  • Close Chrome by clicking X ( not the page, the browser ).
  • Open Chrome. Page loads. Div reads "Waiting for magic."

The state isn't kept between browser closes--even if the cache is. I'm thinking you can implement something similar to make sure they have to login between browser closes. Should work in all browsers too.

critical_error
  • 6,306
  • 3
  • 14
  • 16