Sha256: 2c435420e4994cddabd4aed32d23c8c5d708a91e937575628c664c5e4f2f276a
Contents?: true
Size: 1.47 KB
Versions: 8
Compression:
Stored size: 1.47 KB
Contents
--- layout: compress permalink: '/app.js' --- const $notification = $('#notification'); const $btnRefresh = $('#notification .toast-body>button'); if ('serviceWorker' in navigator) { /* Registering Service Worker */ navigator.serviceWorker.register('{{ "/sw.js" | relative_url }}') .then(registration => { /* in case the user ignores the notification */ if (registration.waiting) { $notification.toast('show'); } registration.addEventListener('updatefound', () => { registration.installing.addEventListener('statechange', () => { if (registration.waiting) { if (navigator.serviceWorker.controller) { $notification.toast('show'); } } }); }); $btnRefresh.click(() => { if (registration.waiting) { registration.waiting.postMessage('SKIP_WAITING'); } $notification.toast('hide'); }); } ); let refreshing = false; /* Detect controller change and refresh all the opened tabs */ navigator.serviceWorker.addEventListener('controllerchange', () => { if (!refreshing) { window.location.reload(); refreshing = true; } }); }
Version data entries
8 entries across 8 versions & 1 rubygems