6 Commits

Author SHA1 Message Date
typist
62350492e9 0.0.29
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m15s
2025-10-29 21:47:03 +08:00
typist
9540c2b550 feat: improve service worker update notifications
- Added toast notifications for users when a new service worker version is available.
- Updated service worker configuration to require manual activation for updates.
- Enhanced user experience by allowing users to choose when to update the application.
2025-10-29 21:46:54 +08:00
typist
006f3d4dbb 0.0.28
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m26s
2025-10-29 21:37:14 +08:00
typist
ff8d497f97 refactor: simplify SidebarFooter component
- Removed the 'need more tools?' link from the SidebarFooter.
- Updated the layout of SidebarFooter to use a flex column for better alignment.
2025-10-29 21:36:44 +08:00
typist
9c2799f7d5 0.0.27
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m14s
2025-10-29 14:49:15 +08:00
typist
dd70f9d886 feat: enhance caching strategies for Google Fonts
- Added caching configurations for Google Fonts stylesheets and webfonts.
- Implemented 'StaleWhileRevalidate' for stylesheets and 'CacheFirst' for font files to optimize loading and improve performance.
2025-10-29 14:49:06 +08:00
4 changed files with 61 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "litek",
"private": true,
"version": "0.0.26",
"version": "0.0.29",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -114,11 +114,7 @@ export const AppSidebar = () => {
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter className="flex flex-row justify-between items-center gap-2">
<SidebarMenuButton variant="outline" asChild>
<a href="mailto:litek@mail.typist.cc">need more tools?</a>
</SidebarMenuButton>
</SidebarFooter>
<SidebarFooter className="flex flex-col gap-2" />
</Sidebar>
);
};

View File

@@ -2,7 +2,7 @@ import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { Toaster } from '@/components/ui/sonner'
import { toast } from 'sonner'
import './index.css'
import { AppRouter } from './router'
@@ -19,11 +19,32 @@ if ('serviceWorker' in navigator && import.meta.env.PROD) {
import('workbox-window').then(({ Workbox }) => {
const wb = new Workbox('/sw.js')
wb.addEventListener('installed', (event) => {
if (event.isUpdate) {
console.log('New service worker installed, reloading page...')
window.location.reload()
}
// 检测到新版本时,在后台下载完成后显示通知
wb.addEventListener('waiting', () => {
// 显示更新通知,右上角弹窗
toast.info('found new version', {
description: 'new content available, click update to get the latest version',
duration: Infinity, // 持续显示,直到用户操作
action: {
label: 'update now',
onClick: () => {
// 用户点击更新按钮
wb.messageSkipWaiting()
}
},
cancel: {
label: 'later',
onClick: () => {
// 用户选择稍后更新,关闭通知
// 新版本会在下次手动刷新时自动激活
}
}
})
})
// 当新的 Service Worker 接管页面时,刷新页面
wb.addEventListener('controlling', () => {
window.location.reload()
})
wb.register()

View File

@@ -43,11 +43,41 @@ export default defineConfig({
statuses: [0, 200]
}
}
},
{
// Google Fonts 样式表缓存
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'google-fonts-stylesheets',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // 1 年
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
{
// Google Fonts 字体文件缓存
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-webfonts',
expiration: {
maxEntries: 30,
maxAgeSeconds: 60 * 60 * 24 * 365 // 1 年
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
],
cleanupOutdatedCaches: true,
clientsClaim: true,
skipWaiting: true
clientsClaim: true, // 新 SW 激活后立即接管
skipWaiting: false // 不自动跳过等待,需要手动触发
}
})
],