forked from shadowwalker/next-pwa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fallback.js
21 lines (20 loc) · 1.12 KB
/
fallback.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict'
self.fallback = async (request) => {
// https://developer.mozilla.org/en-US/docs/Web/API/RequestDestination
switch (request.destination) {
case 'document':
if (process.env.__PWA_FALLBACK_DOCUMENT__) return caches.match(process.env.__PWA_FALLBACK_DOCUMENT__, {ignoreSearch: true})
case 'image':
if (process.env.__PWA_FALLBACK_IMAGE__) return caches.match(process.env.__PWA_FALLBACK_IMAGE__, {ignoreSearch: true})
case 'audio':
if (process.env.__PWA_FALLBACK_AUDIO__) return caches.match(process.env.__PWA_FALLBACK_AUDIO__, {ignoreSearch: true})
case 'video':
if (process.env.__PWA_FALLBACK_VIDEO__) return caches.match(process.env.__PWA_FALLBACK_VIDEO__, {ignoreSearch: true})
case 'font':
if (process.env.__PWA_FALLBACK_FONT__) return caches.match(process.env.__PWA_FALLBACK_FONT__, {ignoreSearch: true})
case '':
if (process.env.__PWA_FALLBACK_DATA__ && request.url.match(/\/_next\/data\/.+\/.+\.json$/i)) return caches.match(process.env.__PWA_FALLBACK_DATA__, {ignoreSearch: true})
default:
return Response.error()
};
}