From 595d66ecd5c3eff6c398e16becb1274acfc03cf4 Mon Sep 17 00:00:00 2001 From: Mridul97 Date: Sun, 6 Jan 2019 03:58:11 +0530 Subject: [PATCH] remove extra clear cache button and isolate cache code (#609) * remove extra clear cache button * isolate cache code * changes --- examples/demo.js | 38 ++------------------------------------ examples/index.html | 7 +------ examples/lib/cache.js | 37 +++++++++++++++++++++++++++++++++++++ examples/lib/sw.js | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 42 deletions(-) create mode 100644 examples/lib/cache.js create mode 100644 examples/lib/sw.js diff --git a/examples/demo.js b/examples/demo.js index b84af806..02c46fef 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -200,42 +200,8 @@ window.onload = function() { } }); - 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(); - }); - + setupCache(); + function updatePreviews(src) { $('#addStep img').remove(); diff --git a/examples/index.html b/examples/index.html index a89a09b4..844936b6 100644 --- a/examples/index.html +++ b/examples/index.html @@ -21,6 +21,7 @@ + @@ -185,12 +186,6 @@ - - - -