Last active
March 27, 2022 11:01
-
-
Save jSayal/fbf9aef54a2a6087494b0d7273bdd5a9 to your computer and use it in GitHub Desktop.
Revisions
-
jSayal revised this gist
Mar 27, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ }; // Refresh website after 12 hours document.addEventListener('visibilitychange', () => { const currentTime = Date.now().getTime(); const lastLoadTime = +(localStorage.getItem('lastLoadTime')) || Date.now(); -
jSayal created this gist
Mar 27, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ <script> const TIME_TO_STALE = 12 * 60 * 60 * 1000; // 12 hours in milliseconds window.onload = () => { localStorage.setItem('lastLoadTime', Date.now()); }; // Refresh website after 12 hours document.addEventListener('visibilitychange', function() { const currentTime = Date.now().getTime(); const lastLoadTime = +(localStorage.getItem('lastLoadTime')) || Date.now(); // Reload - if content is stale if (!document.hidden && currentTime - lastLoadTime >= TIME_TO_STALE) { location.reload(); } }); </script>