Skip to content

Commit

Permalink
Merge pull request #663 from unoplatform/mergify/bp/release/stable/7.…
Browse files Browse the repository at this point in the history
…0/pr-660

Adjust service worker installation (backport #660)
  • Loading branch information
jeromelaban authored Jan 26, 2023
2 parents 6679763 + 2e19592 commit 4920af8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Uno.Wasm.Bootstrap/ShellTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ public override bool Execute()
ExtractAdditionalCSS();
CleanupDist();
PrepareFinalDist();
GenerateConfig();
TouchServiceWorker();
GenerateConfig();
MergeConfig();
GenerateIndexHtml();
GenerateEmbeddedJs();
Expand Down
14 changes: 12 additions & 2 deletions src/Uno.Wasm.Bootstrap/WasmScripts/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ console.debug("[ServiceWorker] Initializing");
self.addEventListener('install', function (e) {
console.debug('[ServiceWorker] Installing offline worker');
e.waitUntil(
caches.open('$(CACHE_KEY)').then(function (cache) {
caches.open('$(CACHE_KEY)').then(async function (cache) {
console.debug('[ServiceWorker] Caching app binaries and content');
return cache.addAll(config.offline_files);

// Add files one by one to avoid failed downloads to prevent the
// worker to fail installing.
for (var i = 0; i < config.offline_files.length; i++) {
try {
await cache.add(config.offline_files[i]);
}
catch (e) {
console.debug(`[ServiceWorker] Failed to fetch ${config.offline_files[i]}`);
}
}
})
);
});
Expand Down

0 comments on commit 4920af8

Please sign in to comment.