{"size": 2379, "ext": "js", "max_stars_repo_path": "sw.js", "max_stars_repo_name": "wang0nya/poetry", "max_stars_repo_stars_event_min_datetime": "2019-05-28T01:23:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-15T10:17:53.000Z", "max_issues_repo_path": "sw.js", "max_issues_repo_name": "wangonya/poetry", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sw.js", "max_forks_repo_name": "wangonya/poetry", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 37.171875, "max_line_length": 91, "alphanum_fraction": 0.5414039512}
// add an install event listener to the service worker
self.addEventListener('install', event => {
    event.waitUntil(
        caches.open('v5').then(cache => cache.addAll([
            '/poetry/',
            '/poetry/index.html',
            '/poetry/404.html',
            '/poetry/css/main.css',
            '/poetry/css/bootstrap.min.css',
            '/poetry/css/normalize.css',
            '/poetry/css/paper-kit.css',
            'https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css',
            '/poetry/css/paper-kit.css',
            '/poetry/js/vendor/modernizr-3.6.0.min.js',
            '/poetry/js/vendor/jquery-3.3.1.min.js',
            '/poetry/js/jquery-ui-1.12.1.custom.min.js',
            '/poetry/js/popper.js',
            '/poetry/js/plugins.js',
            '/poetry/js/main.js',
            '/poetry/js/bootstrap.min.js',
            '/poetry/js/bootstrap-switch.min.js',
            '/poetry/js/paper-kit.js',
            'https://cdn.jsdelivr.net/npm/idb-keyval@3/dist/idb-keyval-iife.min.js'
        ]))
    );
});

// attach a fetch event listener to the service worker,
// then call the respondWith() method on the event to hijack HTTP responses
self.addEventListener('fetch', event => {
    event.respondWith(caches.match(event.request).then(response => {
        // caches.match() always resolves
        // but in case of success response will have value
        if (response !== undefined) {
            return response;
        } else {
            return fetch(event.request).then(response => {
                // response may be used only once
                // we need to save clone to put one copy in cache
                // and serve second one
                let responseClone = response.clone();

                caches.open('v5').then(cache => {
                    cache.put(event.request, responseClone);
                });
                return response;
            }).catch(() => // return Response;
                new Response('Something went wrong :('));
        }
    }));
});

// activate
self.addEventListener('activate', event => {
    const cacheWhitelist = ['v5'];

    event.waitUntil(
        caches.keys().then(keyList => Promise.all(keyList.map(key => {
            if (!cacheWhitelist.includes(key)) {
                return caches.delete(key);
            }
        })))
    );
});