-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v2] [gatsby-plugin-offline] fix: improve service worker initial cach…
…ing (#8183) * Upgrade packages * Use push messages to fetch resources * Resolve the promises properly * Use NetworkFirst for external resources * Change "type" to "api" * Fix integration test
- Loading branch information
1 parent
8c41fe2
commit 68d2fb1
Showing
7 changed files
with
1,263 additions
and
1,541 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
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,23 @@ | ||
/* global workbox */ | ||
|
||
self.addEventListener(`message`, event => { | ||
const { api } = event.data | ||
if (api === `gatsby-runtime-cache`) { | ||
const { resources } = event.data | ||
const cacheName = workbox.core.cacheNames.runtime | ||
|
||
event.waitUntil( | ||
caches.open(cacheName).then(cache => | ||
Promise.all( | ||
resources.map(resource => | ||
cache.add(resource).catch(e => { | ||
// ignore TypeErrors - these are usually due to | ||
// external resources which don't allow CORS | ||
if (!(e instanceof TypeError)) throw e | ||
}) | ||
) | ||
) | ||
) | ||
) | ||
} | ||
}) |
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
Oops, something went wrong.