|
|
|
|
|
|
|
|
'https://fonts.gstatic.com/s/roboto/v27/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2',
|
|
|
'https://fonts.gstatic.com/s/roboto/v27/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2',
|
|
|
'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2',
|
|
|
'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2',
|
|
|
'https://fonts.gstatic.com/s/materialicons/v85/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2',
|
|
|
'https://fonts.gstatic.com/s/materialicons/v85/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.woff2',
|
|
|
|
|
|
'https://fonts.gstatic.com/s/ubuntu/v15/4iCv6KVjbNBYlgoCxCvjsGyNPYZvgw.woff2',
|
|
|
'appsettings.json',
|
|
|
'appsettings.json',
|
|
|
'manifest.json'
|
|
|
'manifest.json'
|
|
|
];
|
|
|
];
|
|
|
|
|
|
|
|
|
console.log('caching app assets');
|
|
|
console.log('caching app assets');
|
|
|
cache.addAll(assets);
|
|
|
cache.addAll(assets);
|
|
|
})
|
|
|
})
|
|
|
);
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
self.skipWaiting();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
// activate event
|
|
|
// activate event
|
|
|
|
|
|
|
|
|
console.log('Now ready to handle fetches!');
|
|
|
console.log('Now ready to handle fetches!');
|
|
|
})
|
|
|
})
|
|
|
);
|
|
|
);
|
|
|
|
|
|
self.clients.claim();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
// fetch events (appsettings are always first fetched from network)
|
|
|
|
|
|
self.addEventListener('fetch', event => {
|
|
|
|
|
|
if (event.request.url.endsWith(appsettings_url)) {
|
|
|
|
|
|
fetch(event.request).then(function (response) {
|
|
|
|
|
|
return caches.open(staticCacheName).then(function (cache) {
|
|
|
|
|
|
console.log('update cache');
|
|
|
|
|
|
cache.put(event.request, response.clone());
|
|
|
|
|
|
return response;
|
|
|
|
|
|
});
|
|
|
|
|
|
}).catch(function () {
|
|
|
|
|
|
return useFallback();
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
event.respondWith(
|
|
|
|
|
|
caches.match(event.request).then(cacheRes => {
|
|
|
|
|
|
return cacheRes || fetch(event.request);
|
|
|
|
|
|
})
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
// fetch events (Network first strategy, no cache update after install)
|
|
|
|
|
|
self.addEventListener('fetch', function (event) {
|
|
|
|
|
|
event.respondWith(fromNetwork(event.request, 6000).catch(function () {
|
|
|
|
|
|
return fromCache(event.request);
|
|
|
|
|
|
}));
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
function useFallback() {
|
|
|
|
|
|
return Promise.resolve(new Response(Appsettings_Fallback, {
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
|
}
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
function fromNetwork(request, timeout) {
|
|
|
|
|
|
return new Promise(function (fulfill, reject) {
|
|
|
|
|
|
var timeoutId = setTimeout(reject, timeout);
|
|
|
|
|
|
fetch(request).then(function (response) {
|
|
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
|
|
fulfill(response);
|
|
|
|
|
|
}, reject);
|
|
|
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
var Appsettings_Fallback = {
|
|
|
|
|
|
"host_base_url": "https://integrate.dynalias.net:9443/Fundvelo/",
|
|
|
|
|
|
"subresource_url_colors": "api/{0}/{1}/fundvelo/colors",
|
|
|
|
|
|
"subresource_url_brands": "api/{0}/{1}/fundvelo/brands",
|
|
|
|
|
|
"subresource_url_types": "api/{0}/{1}/fundvelo/types",
|
|
|
|
|
|
"subresource_url_foundreport": "api/{0}/{1}/fundvelo/fundmeldung",
|
|
|
|
|
|
"subresource_url_missingreport": "api/{0}/{1}/fundvelo/suchauftrag"
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function fromCache(request) {
|
|
|
|
|
|
return caches.open(staticCacheName).then(function (cache) {
|
|
|
|
|
|
return cache.match(request).then(function (matching) {
|
|
|
|
|
|
return matching || Promise.reject('no-match');
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|