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