importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js');

if (workbox) {
  workbox.routing.registerNavigationRoute('https://wopian.me/index.html');

  workbox.routing.registerRoute(
    /\.(?:js|css|html)$/,
    new workbox.strategies.StaleWhileRevalidate({
      cacheName: 'content',
    })
  );

  // Cache the Google Fonts stylesheets with a stale while revalidate strategy.
  workbox.routing.registerRoute(
    /^https:\/\/fonts\.googleapis\.com/,
    new workbox.strategies.StaleWhileRevalidate({
      cacheName: 'google-fonts-stylesheets',
    }),
  );

  // Cache the underlying font files with a cache-first strategy for 1 year.
  workbox.routing.registerRoute(
    /^https:\/\/fonts\.gstatic\.com/,
    new workbox.strategies.CacheFirst({
      cacheName: 'google-fonts-webfonts',
      plugins: [
        new workbox.cacheableResponse.Plugin({
          statuses: [0, 200],
        }),
        new workbox.expiration.Plugin({
          maxAgeSeconds: 60 * 60 * 24 * 365,
          maxEntries: 30,
        }),
      ],
    })
  );

  workbox.routing.registerRoute(
    /\.(?:png|svg|xml|ico|json)$/,
    new workbox.strategies.CacheFirst({
      cacheName: 'icons',
      plugins: [
        new workbox.expiration.Plugin({
          maxEntries: 60,
          maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
        }),
      ],
    })
  );

  addEventListener('message', (event) => {
    if (event.data && event.data.type === 'SKIP_WAITING') {
      skipWaiting();
    }
  });
}

importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js')

if (workbox) {
  workbox.precaching.precacheAndRoute([
    { url: '/index.html', revision: '1' },
    { url: '/main.min.css', revision: '1' },
    { url: '/manifest.json', revision: '1' },
    { url: '/android-chrome-192x192.png', revision: null },
    { url: '/android-chrome-512x512.png', revision: null },
    { url: '/apple-touch-icon.png', revision: null },
    { url: '/browserconfig.xml', revision: null },
    { url: '/favicon-32x32.png', revision: null },
    { url: '/mstile-150x150.png', revision: null },
    { url: '/safari-pinned-tab.svg', revision: null }
  ])
  
  workbox.routing.registerNavigationRoute('/index.html')

  workbox.routing.registerRoute(
    // Cache style resources, i.e CSS files
    ({ request }) => request.destination === 'style',
    // Use cache but update in the background
    new workbox.strategies.StyleWhileRevalidate({ cacheName: 'css-cache' })
  )
}

Update sw.dev.js