How to use the workbox-strategies.NetworkOnly function in workbox-strategies

To help you get started, we’ve selected a few workbox-strategies examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bs-community / blessing-skin-server / resources / assets / src / scripts / sw.ts View on Github external
import { registerRoute } from 'workbox-routing'
import {
  CacheFirst,
  StaleWhileRevalidate,
  NetworkOnly,
} from 'workbox-strategies'
import { ExpirationPlugin } from 'workbox-expiration'

const oneWeek = 7 * 24 * 3600

if (process.env.NODE_ENV === 'development') {
  registerRoute(/\.js/, new NetworkOnly())
  registerRoute(/\.css/, new NetworkOnly())
}

//#region Pictures
registerRoute(
  /\/preview\/\d+/,
  new CacheFirst({
    cacheName: 'texture-preview-v2',
    fetchOptions: {
      credentials: 'omit',
    },
    plugins: [
      new ExpirationPlugin({ maxAgeSeconds: oneWeek, purgeOnQuotaError: true }),
    ],
  }),
)