Last active
January 1, 2019 18:57
-
-
Save jsanta/98ef8d7d554f0c1c5a35a15347b8354a to your computer and use it in GitHub Desktop.
Service worker for PWA Sample app. Please note it uses sw-toolbox.
This file contains hidden or 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
/** | |
* Check out https://googlechromelabs.github.io/sw-toolbox/ for | |
* more info on how to use sw-toolbox to custom configure your service worker. | |
*/ | |
'use strict'; | |
importScripts('./bower_components/sw-toolbox/sw-toolbox.js'); | |
self.toolbox.options.cache = { | |
name: 'ionic-cache' | |
}; | |
// pre-cache our key assets | |
self.toolbox.precache( | |
[ | |
'./main.js', | |
'./runtime.js', | |
'./common.js', | |
'./styles.css', | |
'./polyfills.js', | |
'index.html', | |
'manifest.json' | |
] | |
); | |
// dynamically cache any other local assets | |
self.toolbox.router.any('/*', self.toolbox.fastest); | |
// for any other requests go to the network, cache, | |
// and then only use that cached resource if your user goes offline | |
self.toolbox.router.default = self.toolbox.networkFirst; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment