[英]How to reinstate the Blazor WASM "offline-cache" after a cleanup of the caches?
基本上我有一個升級流程,在 localStorage 和 IndexedDB 清理之間我還執行緩存清理:
window.clearCache = async () => {
const cachesNames = await caches.keys()
for (let i = 0; i < cachesNames.length; i++)
await caches.delete(cachesNames[i])
}
然后我執行Navigation.NavigateTo(Navigation.Uri, forceLoad: true);
強制重新加載網站。
重新加載后,我遇到了這種情況,通常的blazor-resources-/
如果自動填充所有資源,同時offline-cache-<random>
仍然為空。
要恢復離線 WASM 緩存,請使用不同的策略。 我會推薦一個不同的策略並強制緩存重新加載,使用 CACHE_VERSION &。
第一步:新建一個
js
文件
第二步:在
navigator.serviceWorker
object中注冊。
例如yourCustomCacheTriggerReloader.js
文件應該有一個變量
// use this variable to update and trigger your forced upload
// to the client after you delete you files.
`const CACHE_VERSION = 1.0`.
第 3 步:當您刪除時,在您的腳本/或手動中,請更新
CACHE_VERSION
值。 這將告訴/強制瀏覽器/客戶端reload
最新文件。
這里的例子:
// In service-worker.published.js
const CACHE_VERSION = '2021.05.22.001' // Increment each time before deployment.
const cacheNamePrefix = 'offline-cache-';
const cacheName = `${cacheNamePrefix}${CACHE_VERSION}`;
//Note: The original one does not work. Replace
//self.assetsManifest.version withCACHE_VERSION
const cacheName = ${cacheNamePrefix}${self.assetsManifest.version};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.