//https://developers.google.com/web/tools/workbox/guides/get-started
importScripts("/webjars/workbox-sw/4.2.0/build/workbox-sw.js");

/**
 * 이미지 cache
 * Cashe First > Network second
 */
workbox.routing.registerRoute(
    // Cache image files.
    new RegExp("\.(?:png|jpg|jpeg|svg|gif|woff2)$"),
    // Use the cache if it's available.
    new workbox.strategies.CacheFirst({
        // Use a custom cache name.
        cacheName: "wpark-cacheFirst-cache-v1",
        plugins: [
            new workbox.expiration.Plugin({
                // Cache only 40 images.
                maxEntries: 40,
                // Cache for a maximum of a week.
                maxAgeSeconds: 7 * 24 * 60 * 60
            })
        ]
    })
);

/**
 * css, js, html 정보
 * cache first and network to cache update
 */
workbox.routing.registerRoute(
    new RegExp("\.(?:html|js|css|ttf)$"),
    new workbox.strategies.StaleWhileRevalidate({
        cacheName: "wpark-stale-cache-v1",
        plugins: [
            new workbox.expiration.Plugin({
                // Cache only 40 images.
                maxEntries: 50,
                // Cache for a maximum of a week.
                maxAgeSeconds: 24 * 60 * 60
            })
        ]
    })
);

/**
 * 공통 GET 방식 케싱.
 */
workbox.routing.registerRoute(
    new RegExp("/com/cmm/"),
    new workbox.strategies.CacheFirst({
        cacheName: "wpark-common-cache-v1"
    })
);


