Skip to content

fix(ratewise): 裁剪 PWA precache 修復行動冷啟動誤觸離線頁#502

Merged
s123104 merged 3 commits into
mainfrom
fix/ratewise-offline-perf-2026-06
Jun 28, 2026
Merged

fix(ratewise): 裁剪 PWA precache 修復行動冷啟動誤觸離線頁#502
s123104 merged 3 commits into
mainfrom
fix/ratewise-offline-perf-2026-06

Conversation

@s123104

@s123104 s123104 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

問題

行動裝置(尤其 iOS PWA)冷啟動/弱網時,使用者會看到「您目前處於離線狀態」畫面(offline.html,SW 導覽 fallback)。

根因

vite.config.tsinjectManifest.globPatterns**/*.html,SSG 產出每個幣別×金額排列頁(usd-twd/1/10/100/1000…共數百頁)全部被 precache,導致:

  • precache 428 筆 ≈ 34.5 MiB
  • 行動/弱網下 Service Worker 安裝無法在使用者離線前完成 → SW 服務 offline.html

修法(KISS,2 行 globIgnore)

排除幣別頁金額排列子頁,僅保留 app shell(index.html)與各幣別頂層 landing:

'**/[a-z][a-z][a-z]-twd/*/index.html',
'**/twd-[a-z][a-z][a-z]/*/index.html',

金額子頁離線時改由 NavigationRoute → precache 的 index.html SPA shell client-render(行為不變,未改 sw.ts),lazy route chunk 仍在 precache。

指標 修改前 修改後 變化
precache entries 428 222 −48%
precache 體積 ~34.5 MiB ~11.8 MiB −66%
金額子頁洩漏 ~206 0
offline.html / landing / shell 保留

附帶:同步 offline.html 為 SSOT 模板產物(generate-offline-html.mjs,原 committed 版本已 drift)。

驗證

後續(非本 PR;Lighthouse 回歸閘門已綠,屬增益非回歸)

  • motion/react 仍 eager 於首頁多個核心元件(需跨元件動畫重構,UX 回歸面大,故不納入此 hotfix)
  • i18n 四語系 eager 載入(~52KB;改 lazy 涉 SSG hydration 風險)

🤖 Generated with Claude Code

- precache 由 428 筆(約 34.5MB)降至 222 筆(約 11.8MB),排除幣別頁金額排列子頁
- 金額子頁改由 runtime html-cache 與 NavigationRoute 的 index.html SPA shell 還原
- 同步 offline.html 為 SSOT 模板產物(generate-offline-html.mjs 輸出)
- 不改動 sw.ts 導覽邏輯

測試:typecheck 通過;pnpm test 全綠 2476+66;precache 222 筆 11.8MB 金額子頁洩漏 0

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

- Tier 1 precache 僅留 app shell(index.html)+ JS/CSS + 路由 loader 清單 + 4 shell 圖示 + offline.html
- 7.3MB 圖片改 runtime CacheFirst(image-cache 60 筆/30 天);非 shell HTML 由 NavigationRoute 回退 app shell
- 匯率 JSON 改 runtime SWR(GitHub raw + 同域 api/latest、api/pairs,7 天離線備援)
- precache 由 222 筆/11.8MB 降至 92 筆/2.2MB;offline.html 僅作最後手段
- 保留 static-loader-data-manifest precache,離線 SPA 路由導覽不回歸

測試:typecheck 通過;PWA 相關 80 測試全綠;gate 92 筆/2.2MB 無洩漏;loader manifest 已 precache

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@github-actions

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

- verifyAndRepairPrecache 補修 static-loader-data-manifest(離線 SPA 導覽唯一無 runtime 後備的 shell 資產)
- latest-rate-cache maxEntries 20→32,預留擴充幣對餘裕避免 LRU 驅逐離線匯率備援
- 同域 API SWR matcher 加同源判斷,避免 cross-origin pathname 碰撞污染快取
- precache gate 新增 loader-manifest 必含檢查,FORBIDDEN 補 api JSON、巢狀 index.html、點陣圖
- 補回歸測試鎖定上述護欄(共 83 PWA 測試)

測試:typecheck 通過;PWA/gate 83 測試全綠;build precache 92 筆/2.2MB;hardened gate 通過

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@github-actions

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@s123104 s123104 merged commit 31fea7c into main Jun 28, 2026
17 checks passed
@s123104 s123104 deleted the fix/ratewise-offline-perf-2026-06 branch June 28, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant