feat: add PWA support
This commit is contained in:
21
static/manifest.json
Normal file
21
static/manifest.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "技术文章",
|
||||
"short_name": "技术文章",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#317EFB",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/images/website_icon.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "/images/website_icon.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
23
static/service-worker.js
Normal file
23
static/service-worker.js
Normal file
@ -0,0 +1,23 @@
|
||||
const cacheName = 'v1';
|
||||
|
||||
const cacheAssets = [
|
||||
'/',
|
||||
'/index.html',
|
||||
'/style.css',
|
||||
// 可以添加其他需要缓存的资源路径
|
||||
];
|
||||
|
||||
self.addEventListener('install', e => {
|
||||
e.waitUntil(
|
||||
caches.open(cacheName).then(cache => {
|
||||
console.log('Caching files...');
|
||||
return cache.addAll(cacheAssets);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', e => {
|
||||
e.respondWith(
|
||||
fetch(e.request).catch(() => caches.match(e.request))
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user