forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add manifest.json and cache static assets for offline use (#331)
* Add manifest.json * cache static assets for offline use * update cache * add meta theme-color and change static files to be cache * cache the files on network request * caching on first run Signed-off-by: tech4GT <varun.gupta1798@gmail.com> * add a button to clear cache * add styling to clear cache link
- Loading branch information
Showing
5 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"short_name": "IS", | ||
"name": "Image Sequencer", | ||
"icons": [ | ||
{ | ||
"src": "../icons/ic_192.png", | ||
"type": "image/png", | ||
"sizes": "192x192" | ||
}, | ||
{ | ||
"src": "../icons/ic_512.png", | ||
"type": "image/png", | ||
"sizes": "512x512" | ||
} | ||
], | ||
"start_url": "/examples/#steps=", | ||
"background_color": "#428bca", | ||
"display": "standalone", | ||
"scope": "/examples/", | ||
"theme_color": "#428bca" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const staticCacheName = 'image-sequencer-static-v3'; | ||
|
||
self.addEventListener('install', event => { | ||
console.log('Attempting to install service worker'); | ||
}); | ||
|
||
self.addEventListener('activate', function(e) { | ||
console.log('[ServiceWorker] Activate'); | ||
e.waitUntil( | ||
caches.keys().then(function(cacheNames) { | ||
return Promise.all( | ||
cacheNames.filter(function(cacheName){ | ||
return cacheName.startsWith('image-sequencer-') && | ||
cacheName != staticCacheName; | ||
}).map(function(cacheName){ | ||
return caches.delete(cacheName); | ||
}) | ||
); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('fetch', function(event) { | ||
event.respondWith( | ||
caches.open(staticCacheName).then(function(cache) { | ||
return cache.match(event.request).then(function (response) { | ||
return response || fetch(event.request).then(function(response) { | ||
if(event.request.method == "GET") | ||
cache.put(event.request, response.clone()); | ||
return response; | ||
}); | ||
}); | ||
}) | ||
); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.