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