From c11bf7753efa41e18eb76c4da6fe30eab9bc476b Mon Sep 17 00:00:00 2001 From: Alnotz Date: Tue, 24 Dec 2024 14:59:56 +0100 Subject: [PATCH] Service worker if without applicationCache --- bdchapril.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bdchapril.js b/bdchapril.js index 6b35752..fe9f878 100644 --- a/bdchapril.js +++ b/bdchapril.js @@ -1,4 +1,5 @@ -export const checkCacheFunction = () => { +// Cache manager +const checkCacheFunction = () => { if ('applicationCache' in window) { try { var webappCache = window.applicationCache; @@ -42,15 +43,18 @@ export const checkCacheFunction = () => { window.addEventListener("load", loaded, false); webappCache.addEventListener("updateready", updateCache, false); webappCache.addEventListener("error", errorCache, false); + return true; } catch (error) { console.error(`Cache check failed with ${error}.`); + return false; } } else { console.warn("Application caches are not supported!"); + return false; } }; -export const registerServiceWorker = async () => { +const registerServiceWorker = async () => { if ('serviceWorker' in navigator) { try { const registration = await navigator.serviceWorker.register( @@ -74,5 +78,7 @@ export const registerServiceWorker = async () => { } }; -checkCacheFunction(); -registerServiceWorker(); \ No newline at end of file +const HAS_OLD_CACHE = checkCacheFunction(); +if (!HAS_OLD_CACHE) { + registerServiceWorker(); +} \ No newline at end of file