Created
October 12, 2017 20:54
-
-
Save zackargyle/acb95e3a138c850e476cc9a769096990 to your computer and use it in GitHub Desktop.
Sample of Pinterest Mweb service worker generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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