
var APP_SHELL_VERSION = 2;
var APP_SHELL_CACHE = `inventur_shell-v${APP_SHELL_VERSION}`;
var APP_SHELL_URLS = [
    './',
    'css/lib/materialize.min.css',
    'js/lib/materialize.min.js',
    'js/lib/accounting.min.js',
    'js/lib/moment-with-locales.min.js',
    'js/lib/jquery.min.js',
    'js/lib/vue-dev.js',
    'js/lib/vue.min.js',
    'js/lib/vue-resource.min.js'
];
var APP_DATA_VERSION = 1;
var APP_DATA_CACHE = `inventur_data-v${APP_DATA_VERSION}`;
var APP_DATA_URLS = [
    'data/articles.json',
];

var APP_CACHES = [ {
        name: APP_DATA_CACHE,
        urls: APP_DATA_URLS
    },{
        name: APP_SHELL_CACHE,
        urls: APP_SHELL_URLS
    }

]

self.addEventListener('install', function(event){
    event.waitUntil(Promise.all(
        APP_CACHES.map(function (myCache){
            return caches.open(myCache.name)
                .then(function (cache){
                    console.log("[Cache] opened: ", myCache.name);
                    return cache.addAll(myCache.urls);
                });
        })
    ))
});

self.addEventListener('fetch', function(event){
    event.respondWith(
        caches.match(event.request).then(function(response) {
            return response || fetch(event.request);
        })
    );
});

