mirror of
https://github.com/iptv-org/iptv-org.github.io.git
synced 2025-05-11 17:40:05 -04:00
Update service-worker.js
This commit is contained in:
parent
35b78f84cb
commit
15a3e5f54e
1 changed files with 10 additions and 12 deletions
|
@ -53,20 +53,18 @@ self.addEventListener('fetch', event => {
|
|||
const url = new URL(event.request.url)
|
||||
|
||||
const isHttp = url.protocol.startsWith('http')
|
||||
const isDevServerRequest =
|
||||
url.hostname === self.location.hostname && url.port !== self.location.port
|
||||
const isSameOrigin = url.host === self.location.host
|
||||
const isStaticAsset = isSameOrigin && staticAssets.has(url.pathname)
|
||||
const skipBecauseUncached = event.request.cache === 'only-if-cached' && !isStaticAsset
|
||||
if (isHttp && isSameOrigin && !isDevServerRequest && !skipBecauseUncached) {
|
||||
event.respondWith(
|
||||
(async () => {
|
||||
const cachedAsset = isStaticAsset && (await caches.match(event.request))
|
||||
|
||||
if (!isHttp || !isSameOrigin || skipBecauseUncached) return
|
||||
|
||||
event.respondWith(
|
||||
(async () => {
|
||||
let cachedAsset
|
||||
if (isStaticAsset) {
|
||||
cachedAsset = await caches.match(event.request)
|
||||
}
|
||||
|
||||
return cachedAsset || fetchAndCache(event.request)
|
||||
})()
|
||||
)
|
||||
return cachedAsset || fetchAndCache(event.request)
|
||||
})()
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue