I have an HTML page with headers like this:
<meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="expires" content="Wed, 07 Oct 2020 09:50:03 -0600" /> <meta http-equiv="pragma" content="no-cache" />
It is currently 04:45:17
on that date and I want that page to automatically reload at 09:50:03
, at which point the page will have a new expiration date in the met tag, and I want the page to reload based on the new date.
I can reload on an interval, I can use JavaScript to reload if any the files on disk change, but I can’t figure out how to reload based on the expires header. PHP or JavaScript solutions preferred.
Advertisement
Answer
Answer already been given to extending existing answer with further:
const expiresHeader = document.querySelector("meta[http-equiv='expires']").getAttribute('content'); let myinterval =new Date(expiresHeader).getTime() - (new Date()).getTime(); console.log("MyInterval:",myinterval); setInterval(function(){ refreshpage(); }, myinterval ); refreshpage=()=>{ window.location.reload(true); };
<meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="expires" content="Wed, 07 Oct 2020 09:50:03 -0600" /> <meta http-equiv="pragma" content="no-cache" />