Last active
June 10, 2021 16:26
-
-
Save R4356th/7c873fc4161a0855d43601a5d2743ef3 to your computer and use it in GitHub Desktop.
MediaWiki PWA Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="manifest" href="manifest.webmanifest"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Wiki", | |
"short_name": "Wiki", | |
"theme_color": "blue", | |
"background_color": "white", | |
"display": "standalone", | |
"scope": "/", | |
"start_url": "/wiki/Main_Page", | |
"dir": "ltr", | |
"lang": "en", | |
"icons": [ | |
{ | |
"src": "/wiki.png", | |
"sizes": "144x144" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const staticCacheName = 'Wiki'; | |
const assets = [ | |
"/w/load.php/..." | |
]; | |
self.addEventListener("install", (evt) => { | |
evt.waitUntil( | |
caches.open(staticCacheName).then((cache) => { | |
console.log("Caching shell assets..."); | |
cache.addAll(assets); | |
}) | |
); | |
}); | |
self.addEventListener("activate", (evt) => { | |
evt.waitUntil( | |
caches.keys().then((keys) => { | |
return Promise.all( | |
keys | |
.filter((key) => key !== staticCacheName) | |
.map((key) => caches.delete(key)) | |
); | |
}) | |
); | |
}); | |
self.addEventListener("fetch", (evt) => { | |
evt.respondWith( | |
caches.match(evt.request).then((cacheRes) => { | |
return cacheRes || fetch(evt.request); | |
}) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment