mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 17:57:52 +01:00
38 lines
No EOL
937 B
JavaScript
38 lines
No EOL
937 B
JavaScript
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later
|
|
|
|
'use strict';
|
|
|
|
var cacheVersion = 1;
|
|
var currentCache = {
|
|
offline: 'offline-cache' + cacheVersion
|
|
};
|
|
const offlineUrl = 'offline';
|
|
|
|
this.addEventListener('install', event => {
|
|
event.waitUntil(
|
|
caches.open(currentCache.offline).then(function (cache) {
|
|
return cache.addAll([
|
|
offlineUrl
|
|
]);
|
|
})
|
|
);
|
|
});
|
|
|
|
this.addEventListener('fetch', event => {
|
|
if (event.request.mode === 'navigate' || (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) {
|
|
event.respondWith(
|
|
fetch(event.request.url).catch(error => {
|
|
return caches.match(offlineUrl);
|
|
})
|
|
);
|
|
}
|
|
else {
|
|
event.respondWith(caches.match(event.request)
|
|
.then(function (response) {
|
|
return response || fetch(event.request);
|
|
})
|
|
);
|
|
}
|
|
});
|
|
|
|
// @license-end
|