diff --git a/examples/demo.js b/examples/demo.js index 1a901da9..7f1024ab 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -132,4 +132,40 @@ window.onload = function() { step.options.step.imgElement.src = reader.result; } }); + + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('sw.js', { scope: '/examples/' }) + .then(function(registration) { + const installingWorker = registration.installing; + installingWorker.onstatechange = () => { + console.log(installingWorker) + if (installingWorker.state === 'installed') { + location.reload(); + } + } + console.log('Registration successful, scope is:', registration.scope); + }) + .catch(function(error) { + console.log('Service worker registration failed, error:', error); + }); + } + + if ('serviceWorker' in navigator) { + caches.keys().then(function(cacheNames) { + cacheNames.forEach(function(cacheName) { + $("#clear-cache").append(" " + cacheName); + }); + }); + } + + $("#clear-cache").click(function() { + if ('serviceWorker' in navigator) { + caches.keys().then(function(cacheNames) { + cacheNames.forEach(function(cacheName) { + caches.delete(cacheName); + }); + }); + } + location.reload(); + }); }; diff --git a/examples/index.html b/examples/index.html index 4cd7219d..3e4144d0 100644 --- a/examples/index.html +++ b/examples/index.html @@ -7,8 +7,9 @@ + - +