Skip to content

Instantly share code, notes, and snippets.

@zackargyle
Created October 12, 2017 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackargyle/acb95e3a138c850e476cc9a769096990 to your computer and use it in GitHub Desktop.
Save zackargyle/acb95e3a138c850e476cc9a769096990 to your computer and use it in GitHub Desktop.
Sample of Pinterest Mweb service worker generation
/* global $VERSION, $Cache, importScripts, WorkboxSW */
importScripts('https://unpkg.com/workbox-sw@1.1.0/build/importScripts/workbox-sw.prod.v1.1.0.js');
// Add app shell to the webpack-generated precache list
$Cache.precache.push({ url: 'sw-shell.html', revision: $VERSION });
// Register precache list with Workbox
const workbox = new WorkboxSW({ handleFetch: true, skipWaiting: true, clientClaim: true });
workbox.precache($Cache.precache);
// Runtime cache all js
workbox.router.registerRoute(/webapp\/js\/.*\.js/, workbox.strategies.cacheFirst());
// Prefer app-shell for full-page loads
workbox.router.registerNavigationRoute('sw-shell.html', {
blacklist: [
// bunch of non-app routes
],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment