-
Notifications
You must be signed in to change notification settings - Fork 6
/
sw.js
46 lines (40 loc) · 2.09 KB
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(global => {
'use strict';
// Load the sw-tookbox library.
importScripts('/bower_components/sw-toolbox/sw-toolbox.js');
// Turn on debug logging, visible in the Developer Tools' console.
global.toolbox.options.debug = false;
// Set up a handler for HTTP GET requests:
// - /\.ytimg\.com\// will match any requests whose URL contains 'ytimg.com'.
// A narrower RegExp could be used, but just checking for ytimg.com anywhere
// in the URL should be fine for this sample.
// - toolbox.cacheFirst let us to use the predefined cache strategy for those
// requests.
// global.toolbox.router.get(/\.(cloudflare)|(googleapis)\.com\//, global.toolbox.cacheFirst, {
// // Use a dedicated cache for the responses, separate from the default cache.
// cache: {
// name: 'cdnjs',
// // Expire any entries that are older than 30 seconds.
// maxAgeSeconds: 60 * 60 * 100
// }
// });
global.toolbox.router.get('/', global.toolbox.networkFirst, {});
global.toolbox.router.get('/index.html', global.toolbox.networkFirst, {});
global.toolbox.router.get('/draft.html', global.toolbox.networkFirst, {});
global.toolbox.router.get(/(web)|(page)\.rweekly\.com\//, global.toolbox.networkOnly, {});
// global.toolbox.options.cache.maxAgeSeconds = 60 * 15;
// Request the resource from both the cache and the network in parallel.
// Respond with whichever returns first. Usually this will be the cached
// version, if there is one. On the one hand this strategy will always make a
// network request, even if the resource is cached. On the other hand,
// if/when the network request completes the cache is updated, so that future
// cache reads will be more up-to-date.
global.toolbox.router.default = global.toolbox.networkFirst;
global.toolbox.cache.maxEntries = 500;
// Boilerplate to ensure our service worker takes control of the page as soon
// as possible.
global.addEventListener('install',
event => event.waitUntil(global.skipWaiting()));
global.addEventListener('activate',
event => event.waitUntil(global.clients.claim()));
})(self);