Skip to content

Instantly share code, notes, and snippets.

@R4356th
Last active June 10, 2021 16:26
Show Gist options
  • Save R4356th/7c873fc4161a0855d43601a5d2743ef3 to your computer and use it in GitHub Desktop.
Save R4356th/7c873fc4161a0855d43601a5d2743ef3 to your computer and use it in GitHub Desktop.
MediaWiki PWA Example
<link rel="manifest" href="manifest.webmanifest">
{
"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"
}
]
}
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