plugin for PWA
This commit is contained in:
parent
ec5f87cbeb
commit
a120fc8181
5 changed files with 61 additions and 72 deletions
|
|
@ -16,46 +16,9 @@
|
|||
<link rel="icon" type="image/png" href="{{ site.url }}/touch-icon.png" sizes="192x192">
|
||||
<link rel="shortcut icon" href="{{ site.url }}{{ site.icon }}" type="image/png" />
|
||||
<noscript><link rel="stylesheet" href="{{ relBase }}/assets/css/noscripts-20200805.css" /></noscript>
|
||||
<link rel="manifest" href="manifest.json" />
|
||||
<link rel="manifest" href="{{ site.url }}/manifest.json" />
|
||||
<meta name="theme-color" content="{{ site.bg }}"/>
|
||||
<script type="text/javascript">
|
||||
// Registration of service worker
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', function() {
|
||||
navigator.serviceWorker.register("/service-worker.js").then(function(registration) {
|
||||
// Registration was successful
|
||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||
}, function(err) {
|
||||
// registration failed :(
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
else{
|
||||
console.log('Service Workers not supported');
|
||||
}
|
||||
|
||||
// Installation of service worker
|
||||
self.addEventListener('install', function(event) {
|
||||
// Perform install steps
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then(function(cache) {
|
||||
return cache.addAll(urlsToCache);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
event.respondWith(
|
||||
caches.match(event.request, {ignoreSearch:true}).then(response => {
|
||||
return response || fetch(event.request);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue