-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom service worker with Workbox
- Loading branch information
Joni Katajamäki
committed
Dec 13, 2019
1 parent
08ef149
commit 0b9c7ae
Showing
6 changed files
with
635 additions
and
46 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-disable no-restricted-globals, no-undef */ | ||
|
||
// See Workbox docs in https://developers.google.com/web/tools/workbox/modules/workbox-sw | ||
|
||
self.importScripts('/workbox/workbox-v4.3.1/workbox-sw.js') | ||
|
||
workbox.setConfig({ modulePathPrefix: '/workbox/workbox-v4.3.1' }) | ||
//self.workbox.logLevel = self.workbox.LOG_LEVEL.verbose; | ||
|
||
self.addEventListener('install', event => event.waitUntil(self.skipWaiting())) | ||
self.addEventListener('activate', event => | ||
event.waitUntil(self.clients.claim()) | ||
) | ||
|
||
// GENERATED FILES ARE INJECTED HERE BY build-service-worker.js | ||
workbox.precaching.precacheAndRoute([]) | ||
|
||
// API calls precache | ||
workbox.precaching.precacheAndRoute([ | ||
'https://pof-backend-staging.partio.fi/spn-ohjelma-json-taysi/?postGUID=86b5b30817ce3649e590c5059ec88921', | ||
'https://pof-backend-staging.partio.fi/tag-translations-json/', | ||
]) | ||
|
||
// app-shell | ||
workbox.routing.registerRoute('/', new workbox.strategies.NetworkFirst()) | ||
|
||
// webfont-cache | ||
const webFontHandler = new workbox.strategies.CacheFirst({ | ||
cacheName: 'webfont-cache', | ||
cacheExpiration: { | ||
maxEntries: 20, | ||
}, | ||
cacheableResponse: { statuses: [0, 200] }, | ||
}) | ||
workbox.routing.registerRoute( | ||
/https:\/\/fonts.googleapis.com\/.*/, | ||
webFontHandler | ||
) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
globDirectory: './build/', | ||
globPatterns: ['**/*.{html,js,css,png,jpg,json}'], | ||
globIgnores: [ | ||
'service-worker-default.js', | ||
'service-worker.js', | ||
'workbox-sw.js', | ||
'index.html', | ||
], | ||
swSrc: './src/service-worker-template.js', | ||
swDest: './build/service-worker-default.js', | ||
} |
Oops, something went wrong.