Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
wushuangs committed Nov 14, 2024
1 parent b7818fc commit da0d701
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 17 additions & 1 deletion packages/frontend/quasar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,23 @@ module.exports = configure(function (ctx) {

pwa: {
workboxPluginMode: 'InjectManifest', // 'GenerateSW' or 'InjectManifest'
workboxOptions: {}, // only for GenerateSW
workboxOptions: {
runtimeCaching: [
{
urlPattern: new RegExp('/public/'),
handler: 'NetworkOnly'
},
{
urlPattern: /\/api\/.*/,
handler: 'NetworkFirst',
options: {
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
}, // only for GenerateSW

manifest: {
name: 'Olares',
Expand Down
6 changes: 2 additions & 4 deletions packages/frontend/src-pwa/custom-service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare const self: ServiceWorkerGlobalScope &
import { precacheAndRoute } from 'workbox-precaching';
// import { clientsClaim } from 'workbox-core';
import { registerRoute } from 'workbox-routing';
import { NetworkOnly, StaleWhileRevalidate } from 'workbox-strategies';
import { NetworkOnly } from 'workbox-strategies';
// 放在顶部,sw获得控制权,不然是下次打开页面获得
// clientsClaim();
// // 跳过等待
Expand Down Expand Up @@ -40,10 +40,8 @@ self.addEventListener('fetch', (event) => {
// 自定义缓存策略
// 例如:网络优先策略
registerRoute(
({ request, url }) => {
({ request }) => {
console.log('Request mode:', request);
url.origin === self.location.origin && url.pathname.startsWith('/public/'),
new StaleWhileRevalidate();
return request.mode === 'navigate';
}, // 这是 Workbox 推荐的检查 document 请求的方式
new NetworkOnly({
Expand Down

0 comments on commit da0d701

Please sign in to comment.