3 self.addEventListener('fetch', function(event) {
4 if(event.request.url.match(/^\/([a-z]*\.(js|css)|css\/|assets\/)/)) {
5 let responder = cache => {
6 return cache.match(event.request).then(match => {
10 return cache.match(event.request, {ignoreSearch: true}).then(match => {
11 if(match) cache.delete(match);
13 return fetch(event.request).then(response => {
14 cache.put(event.request, response.clone());
23 event.respondWith(responder(cache));
26 caches.open("v1").then(openedCache => {
28 return responder(cache);
35 let lastNotification = null;
37 self.addEventListener('push', function(event) {
39 fetch("/check-notifications?format=push")
40 .then(res => res.json())
41 .then(notifications => {
42 if(!notifications) return;
43 for(var i=0; i < notifications.length; i++) {
44 if(lastNotification === notifications[i]._id) {
45 lastNotification = notifications[i]._id;
48 self.registration.showNotification(notifications[i].message);
54 self.addEventListener('notificationclick', function(event) {
55 event.waitUntil(clients.openWindow("/push/go-inbox"));
58 self.addEventListener('install', (event) => {
60 caches.open("v1").then(openedCache => { cache = openedCache; }).then(self.skipWaiting())
64 self.addEventListener('activate', (event) => {
65 event.waitUntil(clients.claim());