
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',
];

self.addEventListener('install', function(event){
    event.waitUntil(
        caches.open(APP_SHELL_CACHE)
            .then(function(cache){
                console.log("[Cache] opened: ", APP_SHELL_CACHE);
                return cache.addAll(APP_SHELL_URLS);
            })
    ).waitUntil(
        caches.open(APP_DATA_CACHE)
            .then(function(cache){
                console.log("[Cache] opened: ", APP_DATA_CACHE);
                return cache.addAll(APP_DATA_URLS);
            })
    );
});

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

