Skip to content

Instantly share code, notes, and snippets.

@kevinah95
Created August 7, 2018 00:11
Show Gist options
  • Select an option

  • Save kevinah95/2b84ba5c92fd21e2b3b2a4ee0009b160 to your computer and use it in GitHub Desktop.

Select an option

Save kevinah95/2b84ba5c92fd21e2b3b2a4ee0009b160 to your computer and use it in GitHub Desktop.
custom-sw.js for Using Workbox with Create React App (Without Ejecting) Medium
// See https://developers.google.com/web/tools/workbox/guides/configure-workbox
workbox.core.setLogLevel(workbox.core.LOG_LEVELS.debug);
self.addEventListener('install', event => event.waitUntil(self.skipWaiting()));
self.addEventListener('activate', event => event.waitUntil(self.clients.claim()));
// We need this in Webpack plugin (refer to swSrc option): https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin#full_injectmanifest_config
workbox.precaching.precacheAndRoute(self.__precacheManifest);
// app-shell
workbox.routing.registerRoute("/", workbox.strategies.networkFirst());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment