Service worker if without applicationCache
This commit is contained in:
parent
add5fc6132
commit
c11bf7753e
1 changed files with 10 additions and 4 deletions
12
bdchapril.js
12
bdchapril.js
|
@ -1,4 +1,5 @@
|
||||||
export const checkCacheFunction = () => {
|
// Cache manager
|
||||||
|
const checkCacheFunction = () => {
|
||||||
if ('applicationCache' in window) {
|
if ('applicationCache' in window) {
|
||||||
try {
|
try {
|
||||||
var webappCache = window.applicationCache;
|
var webappCache = window.applicationCache;
|
||||||
|
@ -42,15 +43,18 @@ export const checkCacheFunction = () => {
|
||||||
window.addEventListener("load", loaded, false);
|
window.addEventListener("load", loaded, false);
|
||||||
webappCache.addEventListener("updateready", updateCache, false);
|
webappCache.addEventListener("updateready", updateCache, false);
|
||||||
webappCache.addEventListener("error", errorCache, false);
|
webappCache.addEventListener("error", errorCache, false);
|
||||||
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Cache check failed with ${error}.`);
|
console.error(`Cache check failed with ${error}.`);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn("Application caches are not supported!");
|
console.warn("Application caches are not supported!");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const registerServiceWorker = async () => {
|
const registerServiceWorker = async () => {
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
try {
|
try {
|
||||||
const registration = await navigator.serviceWorker.register(
|
const registration = await navigator.serviceWorker.register(
|
||||||
|
@ -74,5 +78,7 @@ export const registerServiceWorker = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
checkCacheFunction();
|
const HAS_OLD_CACHE = checkCacheFunction();
|
||||||
|
if (!HAS_OLD_CACHE) {
|
||||||
registerServiceWorker();
|
registerServiceWorker();
|
||||||
|
}
|
Loading…
Reference in a new issue