Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sample of Pinterest Mweb service worker generation
/* global $VERSION, $Cache, importScripts, WorkboxSW */
// 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 });
// 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