Skip to content

Instantly share code, notes, and snippets.

@hizo
Created December 29, 2016 01:12
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 hizo/cc0ae8198b024b40b3b9b869ef4dd2df to your computer and use it in GitHub Desktop.
Save hizo/cc0ae8198b024b40b3b9b869ef4dd2df to your computer and use it in GitHub Desktop.
Service workers easy way
swPrecache.write(path.resolve(__dirname, `../public/service-worker.js`), {
cacheId: `know-it-all`,
filename: `service-worker.js`,
stripPrefix: `public/`,
staticFileGlobs: [
`public/app.*.js`, // don't include the polyfills version
`public/*.{html,ico,json,png}`,
],
dontCacheBustUrlsMatching: [
/\.(js|json)$/, // I'm cache busting js and json files myself
],
skipWaiting: true,
}, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
// ...
// in client
if (`serviceWorker` in navigator) {
navigator.serviceWorker.register(`service-worker.js`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment