<commit_before>/* VARS */

// enables debug logging
var IS_DEBUG_ENABLED = false;

const CACHE_NAME = 'v8';

/* CACHE REQUIRED ITEMS */
const urlsToCache = [
    // html
    '/',
    '/index.html',

    // css
    '/css/non-critical.css',

    // js
    '/js/main.min.js'
];

self.addEventListener('install', (event) => {
    //log('SW is installed');
    self.addEventListener('message', (event)=> {
        //log('Handling a message', event);
        if (event.data.IS_DEBUG_ENABLED !== undefined) {
            IS_DEBUG_ENABLED = event.data.IS_DEBUG_ENABLED;
        }
    });
    // OLD SW MIGHT BE STILL ACTIVE HERE
    event.waitUntil(
        caches.open(CACHE_NAME)
            .then((cache) =>cache.addAll(urlsToCache))
            .catch((err)=> {
                logError(`Error opening the cache "${CACHE_NAME}": ${err}`);
            })
    );
});

/* DELETE PREVIOUS CACHES */
self.addEventListener('activate', (event) => {
    //log('SW is activated');
    // CURRENT SW TAKES CONTROL, OLD ISN'T ACTIVE HERE
    event.waitUntil(
        caches.keys()
            .then((cacheNames) => {
                return Promise.all(
                    cacheNames.map((cacheName) => {
                        if (cacheName !== CACHE_NAME) {
                            return caches.delete(cacheName);
                        }
                    })
                );
            })
            .catch((err) => {
                logError(`Error reading cache keys for "${CACHE_NAME}": ${err}`);
            })
    );
});

/* FETCH */
self.addEventListener('fetch', (event) => {
    event.respondWith(
        caches.match(event.request)
            .then((responseFromCache) => {
                    if (responseFromCache) {
                        // Fetching request as usually
                        // and serve cached version only in cases of errors
                        // (offline mode, network or server errors etc.)
                        return fetch(event.request.clone())
                            .then((response) => response)
                            .catch(()=> {
                                log('* [Serving cached because of fetching error]: ' + event.request.url);
                                return responseFromCache;
                            });
                    }<commit_msg>Output to console when cached content is serving<commit_after>/* VARS */

// enables debug logging
var IS_DEBUG_ENABLED = false;

const CACHE_NAME = 'v8';

/* CACHE REQUIRED ITEMS */
const urlsToCache = [
    // html
    '/',
    '/index.html',

    // css
    '/css/non-critical.css',

    // js
    '/js/main.min.js'
];

self.addEventListener('install', (event) => {
    //log('SW is installed');
    self.addEventListener('message', (event)=> {
        //log('Handling a message', event);
        if (event.data.IS_DEBUG_ENABLED !== undefined) {
            IS_DEBUG_ENABLED = event.data.IS_DEBUG_ENABLED;
        }
    });
    // OLD SW MIGHT BE STILL ACTIVE HERE
    event.waitUntil(
        caches.open(CACHE_NAME)
            .then((cache) =>cache.addAll(urlsToCache))
            .catch((err)=> {
                logError(`Error opening the cache "${CACHE_NAME}": ${err}`);
            })
    );
});

/* DELETE PREVIOUS CACHES */
self.addEventListener('activate', (event) => {
    //log('SW is activated');
    // CURRENT SW TAKES CONTROL, OLD ISN'T ACTIVE HERE
    event.waitUntil(
        caches.keys()
            .then((cacheNames) => {
                return Promise.all(
                    cacheNames.map((cacheName) => {
                        if (cacheName !== CACHE_NAME) {
                            return caches.delete(cacheName);
                        }
                    })
                );
            })
            .catch((err) => {
                logError(`Error reading cache keys for "${CACHE_NAME}": ${err}`);
            })
    );
});

/* FETCH */
self.addEventListener('fetch', (event) => {
    event.respondWith(
        caches.match(event.request)
            .then((responseFromCache) => {
                    if (responseFromCache) {
                        // Fetching request as usually
                        // and serve cached version only in cases of errors
                        // (offline mode, network or server errors etc.)
                        return fetch(event.request.clone())
                            .then((response) => response)
                            .catch(()=> {
                                console.log('* [Serving cached because of fetching error]: ' + event.request.url);
                                return responseFromCache;
                            });
                    }
{'fraction_non_alphanumeric': 0.1343982960596379, 'fraction_numerical': 0.0004259850905218317, 'mean_word_length': 1.4119157678479712, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2082598', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1254, 'n_words': 275}