Skip to content

Instantly share code, notes, and snippets.

@jsanta
Last active January 1, 2019 18:57
Show Gist options
  • Save jsanta/98ef8d7d554f0c1c5a35a15347b8354a to your computer and use it in GitHub Desktop.
Save jsanta/98ef8d7d554f0c1c5a35a15347b8354a to your computer and use it in GitHub Desktop.
Service worker for PWA Sample app. Please note it uses sw-toolbox.
/**
* 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