forked from imsyy/SNav
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
底层用户
committed
Mar 22, 2022
1 parent
52431d9
commit 2513963
Showing
12 changed files
with
114 additions
and
28 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,48 @@ | ||
const CURCACHE = 'CURCACHE_test_1' | ||
const RUNTIME = 'runtime'; | ||
const CURCACHE_URLS = [ | ||
'./', | ||
'index.html' | ||
] | ||
self.addEventListener('install', e => { | ||
e.waitUntil( | ||
//存储缓存路径对应的资源 | ||
caches.open(CURCACHE).then(cache => { | ||
cache.addAll(CURCACHE_URLS) | ||
}).then( | ||
self.skipWaiting() | ||
) | ||
) | ||
}) | ||
|
||
//代理请求,使用缓存,请求发送之前 | ||
self.addEventListener('fetch', e => { | ||
e.respondWith( | ||
//缓存是否匹配 | ||
caches.match(e.request).then(function (response) { | ||
if (response != null) { | ||
//命中缓存返回缓存,结束请求 | ||
return response | ||
} | ||
//未命中缓存,正常请求 | ||
return fetch(e.request.url) | ||
}) | ||
) | ||
}); | ||
|
||
//假设上个版本的key为precache_test_2 反正不等于CURCACHE | ||
self.addEventListener('activate', e => { | ||
e.waitUntil( | ||
//遍历当前缓存keys | ||
caches.keys().then(cacheNames => { | ||
return Promise.all( | ||
cacheNames.map(function (cacheName) { | ||
//是否等于当前key,保留自己 | ||
if (cacheName !== CURCACHE) { | ||
return caches.delete(cacheName); | ||
} | ||
}) | ||
) | ||
}).then(() => self.clients.claim()) | ||
) | ||
}) |
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,30 @@ | ||
{ | ||
"name": "Snavigation", | ||
"short_name": "Snavigation", | ||
"display": "standalone", | ||
"start_url": "/", | ||
"theme_color": "#efefef", | ||
"background_color": "#333333", | ||
"icons": [ | ||
{ | ||
"src": "img/icon/favicon_32.png", | ||
"sizes": "32x32", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "img/icon/favicon_64.png", | ||
"sizes": "64x64", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "img/icon/favicon_128.png", | ||
"sizes": "128x128", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "img/icon/favicon_144.png", | ||
"sizes": "144x144", | ||
"type": "image/png" | ||
} | ||
] | ||
} |