Skip to content

Commit

Permalink
Update native cache & sw init
Browse files Browse the repository at this point in the history
  • Loading branch information
aglitchman committed Oct 9, 2022
1 parent be9b998 commit 56bca60
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions yagames/manifests/web/engine_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,27 @@
// {{#yagames.manifest_url}}
isNativeCache = ysdk.yandexApp && ysdk.yandexApp.enabled;
// {{/yagames.manifest_url}}
if ("serviceWorker" in navigator && !isNativeCache) {
navigator.serviceWorker.register("{{yagames.service_worker_url}}").then(
function (registration) {
console.log("YaGames: Service Worker registration successful with scope", registration.scope);
},
function (err) {
console.log("YaGames: Service Worker registration failed", err);
}
);
if ("serviceWorker" in navigator) {
if (isNativeCache) {
// Force unregister all Service Workers
navigator.serviceWorker.getRegistrations().then(function (registrations) {
registrations.forEach(function (registration) {
registration.unregister().then(function (isUnregistered) {
console.info("YaGames: Service Worker unregistration result", isUnregistered);
});
});
});
} else {
// Register Service Worker
navigator.serviceWorker.register("{{yagames.service_worker_url}}").then(
function (registration) {
console.info("YaGames: Service Worker registration successful with scope", registration.scope);
},
function (err) {
console.info("YaGames: Service Worker registration failed", err);
}
);
}
}
// {{/yagames.service_worker_url}}

Expand Down

0 comments on commit 56bca60

Please sign in to comment.