-
Notifications
You must be signed in to change notification settings - Fork 84
/
sw-precache-config.js
67 lines (60 loc) · 2.24 KB
/
sw-precache-config.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Config for offline caching with Service Worker Precache
https://www.polymer-project.org/1.0/toolbox/service-worker
https://github.com/GoogleChrome/sw-precache/blob/master/GettingStarted.md */
module.exports = {
/* cacheId is string used to distinguish the caches created by different web applications
that are served off of the same origin and path.
While serving completely different sites from the same URL is not likely to be an issue
in a production environment, it avoids cache-conflicts when testing various projects
all served off of http://localhost. */
cacheId: 'progressive-app-v1',
/* Array of one or more string patterns that will be passed in to glob.
All files matching these globs will be automatically precached by the generated service worker. */
staticFileGlobs: [
'/index.html',
'/manifest.json',
'/bower_components/webcomponentsjs/webcomponents-lite.min.js',
'/data/locales/**/*.json',
'/fonts/**/*.*',
'/images/**/*.*'
],
/* Fallback document, to be served when the requested URL is not in the cache.
For a single—page app, this is typically the same as the entrypoint. */
navigateFallback: '/index.html',
/* Whitelist includes all files except those that end in .html (for HTML imports) and
ones with /data/ in the path (for dynamically-loaded data). */
navigateFallbackWhitelist: [/^(?!.*\.html$|\/data\/).*/],
/* Runtime Caching for Dynamic Content
https://github.com/GoogleChrome/sw-precache/blob/master/GettingStarted.md#runtime-caching-for-dynamic-content */
runtimeCaching: [{
/* Google Analytics */
urlPattern: /https?:\/\/((www|ssl)\.)?google-analytics\.com\/analytics.js/,
handler: 'networkFirst'
}, {
/* Google Fonts
urlPattern: /https?:\/\/fonts.+/,
handler: 'cacheFirst'
}, { */
/* Examples */
urlPattern: /^https:\/\/example\.com\/api/,
handler: 'networkFirst'
}, {
urlPattern: /\/data\/images\/.*/,
handler: 'cacheFirst',
options: {
cache: {
maxEntries: 200,
name: 'images-cache'
}
}
}, {
urlPattern: /\/data\/articles\/.*json/,
handler: 'fastest',
options: {
cache: {
maxEntries: 100,
name: 'articles-cache'
}
}
}]
};