Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if chrome is loading a cached page?

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?

like image 264
Jensen010 Avatar asked Nov 08 '22 03:11

Jensen010


1 Answers

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.

like image 178
Critical Error Avatar answered Nov 09 '22 23:11

Critical Error