refactor(pwa): 移除PWA相关配置和Service Worker实现
- 删除 about.html 和 index.html 中的 PWA meta 标签 - 移除 PWA 注册脚本和服务工作器文件 js/sw.js - 清理 Apple 和 Windows PWA 支持的相关配置 - 简化应用加载逻辑,不再依赖离线缓存机制 - 更新 manifest.json 引用及相关主题颜色设置 - 优化移动端显示设置,去除 user-scalable 属性
This commit is contained in:
33
about.html
33
about.html
@@ -5,9 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
|
||||
<title>关于我 - Honesty</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<!-- PWA相关配置 -->
|
||||
<meta name="theme-color" content="#6c5ce7">
|
||||
<link rel="manifest" href="./manifest.json">
|
||||
|
||||
|
||||
<!--SEO信息 -->
|
||||
<meta name="description" content="关于Honesty,关于HeHouHui,关于HeHui,关于明厚, About Me Honesty, About Me HeHouHui, About Me HeHui">
|
||||
@@ -430,34 +428,5 @@
|
||||
initFormatter();
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- PWA注册 -->
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function() {
|
||||
navigator.serviceWorker.register('./js/sw.js')
|
||||
.then(function(registration) {
|
||||
console.log('SW registered: ', registration);
|
||||
})
|
||||
.catch(function(registrationError) {
|
||||
console.log('SW registration failed: ', registrationError);
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Apple PWA支持 -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="apple-mobile-web-app-title" content="Honesty">
|
||||
<link rel="apple-touch-icon" href="./images/avatar.jpeg">
|
||||
|
||||
<!-- Windows PWA支持 -->
|
||||
<meta name="msapplication-TileImage" content="./images/avatar.jpeg">
|
||||
<meta name="msapplication-TileColor" content="#6c5ce7">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
|
||||
<!-- 其他PWA相关meta标签 -->
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
</body>
|
||||
</html>
|
||||
32
index.html
32
index.html
@@ -13,9 +13,6 @@
|
||||
<meta name="keywords" content="Honesty,HeHouHui,HeHui,明厚">
|
||||
<meta name="author" content="Honesty">
|
||||
|
||||
<!-- PWA相关配置 -->
|
||||
<meta name="theme-color" content="#6c5ce7">
|
||||
<link rel="manifest" href="./manifest.json">
|
||||
|
||||
<!-- 社交平台分享优化 -->
|
||||
<!-- Open Graph / Facebook -->
|
||||
@@ -416,34 +413,5 @@
|
||||
}()
|
||||
}({id: "3OBGjwDdEIRS7XZ1", ck: "3OBGjwDdEIRS7XZ1"});
|
||||
</script>
|
||||
|
||||
<!-- PWA注册 -->
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function () {
|
||||
navigator.serviceWorker.register('./js/sw.js')
|
||||
.then(function (registration) {
|
||||
console.log('SW registered: ', registration);
|
||||
})
|
||||
.catch(function (registrationError) {
|
||||
console.log('SW registration failed: ', registrationError);
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Apple PWA支持 -->
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="apple-mobile-web-app-title" content="Honesty">
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
||||
|
||||
<!-- Windows PWA支持 -->
|
||||
<meta name="msapplication-TileImage" content="/images/avatar.jpeg">
|
||||
<meta name="msapplication-TileColor" content="#6c5ce7">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
|
||||
<!-- 其他PWA相关meta标签 -->
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
</body>
|
||||
</html>
|
||||
80
js/sw.js
80
js/sw.js
@@ -1,80 +0,0 @@
|
||||
// Service Worker for PWA
|
||||
const CACHE_NAME = 'honesty-home-v1.0.1';
|
||||
const urlsToCache = [
|
||||
'./index.html',
|
||||
'./about.html',
|
||||
'./css/style.css',
|
||||
'./css/about.css',
|
||||
'./css/artalk.css',
|
||||
'./js/config.js',
|
||||
'./js/main.js',
|
||||
'./js/about.js'
|
||||
];
|
||||
|
||||
// 安装事件 - 缓存资源
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then(cache => {
|
||||
console.log('Opened cache');
|
||||
return cache.addAll(urlsToCache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// 获取事件 - 拦截网络请求
|
||||
self.addEventListener('fetch', event => {
|
||||
// 对于非GET请求或者不是同源请求,直接跳过
|
||||
if (event.request.method !== 'GET' || !event.request.url.startsWith(self.location.origin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(response => {
|
||||
// 如果在缓存中找到响应,则返回缓存的资源
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// 克隆请求,因为请求是一个流,只能被消费一次
|
||||
const fetchRequest = event.request.clone();
|
||||
|
||||
// 如果没有在缓存中找到,则发起网络请求
|
||||
return fetch(fetchRequest).then(response => {
|
||||
// 检查响应是否有效
|
||||
if (!response || response.status !== 200 || response.type !== 'basic') {
|
||||
return response;
|
||||
}
|
||||
|
||||
// 克隆响应,因为响应是一个流,只能被消费一次
|
||||
const responseToCache = response.clone();
|
||||
|
||||
// 打开缓存并将响应添加到缓存中
|
||||
caches.open(CACHE_NAME)
|
||||
.then(cache => {
|
||||
cache.put(event.request, responseToCache);
|
||||
});
|
||||
|
||||
return response;
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// 激活事件 - 清理旧缓存
|
||||
self.addEventListener('activate', event => {
|
||||
const cacheWhitelist = [CACHE_NAME];
|
||||
|
||||
event.waitUntil(
|
||||
caches.keys().then(cacheNames => {
|
||||
return Promise.all(
|
||||
cacheNames.map(cacheName => {
|
||||
if (cacheWhitelist.indexOf(cacheName) === -1) {
|
||||
return caches.delete(cacheName);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user