From 65bd645dd9657dd38a7b94d0402d2d610eb4a3ed Mon Sep 17 00:00:00 2001 From: TLRZ Seyfferth Date: Sun, 14 Jan 2018 17:31:17 +0100 Subject: [PATCH] app manifest --- index.html | 11 +++++++++++ manifest.json | 25 ++++++++++++++++++++++++ serviceWorker.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 manifest.json create mode 100644 serviceWorker.js diff --git a/index.html b/index.html index 1fb7032..d29c8be 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,7 @@ + @@ -169,6 +170,16 @@ + diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..99e1fff --- /dev/null +++ b/manifest.json @@ -0,0 +1,25 @@ +{ + "manifest_version": 1, + "name": "chrosey.de Inventur", + "version": "1.0", + + "default_locale": "de", + "description": "Inventur-Helfer", + "short_name" : "1894. Inventur", + "start_url": "https://chrosey.de/apps/inv", + "icons": [ + { + "src": "/favicons/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/favicons/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#303F9F", + "background_color": "#C5CAE9", + "display": "standalone" +} diff --git a/serviceWorker.js b/serviceWorker.js new file mode 100644 index 0000000..029215a --- /dev/null +++ b/serviceWorker.js @@ -0,0 +1,49 @@ +var CACHE_NAME = "inventur_cache-v1"; +var urlsToCache = [ + '.', + 'js/app.js', + 'js/vue.js', + 'js/accounting.min.js', + 'js/moment-with-locales.min.js', + 'js/model/article.js', + 'js/model/inventory_article.js' +]; + +self.addEventListener('install', function(event){ + event.waitUntil( + caches.open(CACHE_NAME) + .then(function(cache){ + console.log("Cache opened"); + return cache.addAll(urlsToCache); + }) + ); +}); + +self.addEventListener('fetch', function(event){ + event.respondWith( + caches.match(event.request) + .then(function(response){ + if (response) { + return response; + } + var fetchRequest = event.request.clone(); + + return fetch(fetchRequest).then( + function(response){ + if(!response || response.status !== 200 || response.type !== 'basic') { + return response; + } + + var responseToCache = response.clone(); + caches.open(CACHE_NAME) + .then(function(cache){ + cache.put(event.request, responseToCache); + }); + + return response; + } + ) + }) + ); +}); +