
var APP_SHELL_VERSION = 2;
var APP_SHELL_CACHE = "inventur_shell-${APP_SHELL_VERSION}";
var urlsToCache = [
    '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',
    'fonts/Roboto/*',
    '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(urlsToCache);
            })
    );
});

self.addEventListener('fetch', function(event){
    event.respondWith(
        caches.open(APP_SHELL_CACHE).then(function(cache) {
            return fetch(event.request)
                .then(function(response){
                    cache.put(event.request, response.clone());
                    return response;
                });
        })
    );
});

