reload_on_sentinel.js (Source)

(function pollSentinel(interval = 1000) {
  let lastContent = null;
  async function checkForChange() {
    try {
      const response = await fetch('/sentinel', { cache: 'no-store' });
      if (!response.ok) throw new Error('Fetch failed');
      const text = await response.text();
      if (lastContent === null) {
        lastContent = text;
      } else if (text !== lastContent) {
        console.log('Sentinel changed — reloading...');
        location.reload();
      }
    } catch (err) {
      console.error('Error checking sentinel:', err);
    }
  }
  setInterval(checkForChange, interval);
})();