Created
June 1, 2018 13:31
-
-
Save huang-xiao-jian/b5605a02d5c72d49121c64ddb40b9090 to your computer and use it in GitHub Desktop.
配置 workbox PWA
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
/** | |
* @description - service worker strategy | |
* @author - huang.jian <hjj491229492@hotmail.com> | |
*/ | |
/* eslint-env worker */ | |
/* global workbox */ | |
// import workbox library | |
importScripts( | |
'https://storage.googleapis.com/workbox-cdn/releases/3.2.0/workbox-sw.js' | |
); | |
workbox.setConfig({ | |
debug: true, | |
}); | |
workbox.core.setCacheNameDetails({ | |
prefix: 'babycherry', | |
suffix: 'v1', | |
}); | |
workbox.core.setLogLevel(workbox.core.LOG_LEVELS.debug); | |
// route strategy | |
workbox.routing.registerRoute( | |
/^https:\/\/cdn\.bootcss\.com./, | |
workbox.strategies.staleWhileRevalidate({ | |
cacheName: 'CDN' | |
}), | |
); | |
workbox.routing.registerNavigationRoute('/index.html', { | |
whitelist: [/^\/pwa/], | |
blacklist: [ | |
/\.(js|css|jpe?g|png|gif|pdf)$/, | |
] | |
}); | |
workbox.precaching.precacheAndRoute([]); |
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
/** | |
* @description - workbox configuration for PWA | |
* @author - huang.jian <hjj491229492@hotmail.com> | |
*/ | |
module.exports = { | |
swSrc: 'public/sw.js', | |
swDest: 'dist/client/sw.js', | |
globDirectory: 'dist/client', | |
globPatterns: ['**/*.{png,ico,html,json,jpg,js,css}'], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment