v1.4.8r Add service worker to cache the webpages, but i dont know if it works
This commit is contained in:
Vendored
+6877
-3
File diff suppressed because one or more lines are too long
Vendored
+7119
-3
File diff suppressed because one or more lines are too long
Vendored
+7166
-3
File diff suppressed because one or more lines are too long
@@ -0,0 +1,81 @@
|
|||||||
|
const staticCacheName = 'site-static-v2';
|
||||||
|
const dynamicCacheName = 'site-dynamic-v1';
|
||||||
|
const assets = [
|
||||||
|
'/',
|
||||||
|
'/css/app.css',
|
||||||
|
'/css/normalize.css',
|
||||||
|
'/css/webapp.css',
|
||||||
|
'/css/webappdark.css',
|
||||||
|
'/home',
|
||||||
|
'/events'
|
||||||
|
];
|
||||||
|
|
||||||
|
// install event
|
||||||
|
self.addEventListener('install', evt => {
|
||||||
|
//console.log('service worker installed');
|
||||||
|
evt.waitUntil(
|
||||||
|
caches.open(staticCacheName).then((cache) => {
|
||||||
|
console.log('caching shell assets');
|
||||||
|
return cache.addAll(assets);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// activate event
|
||||||
|
self.addEventListener('activate', evt => {
|
||||||
|
//console.log('service worker activated');
|
||||||
|
evt.waitUntil(
|
||||||
|
caches.keys().then(keys => {
|
||||||
|
//console.log(keys);
|
||||||
|
return Promise.all(keys
|
||||||
|
.filter(key => key !== staticCacheName && key !== dynamicCacheName)
|
||||||
|
.map(key => caches.delete(key))
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// fetch event
|
||||||
|
self.addEventListener('fetch', evt => {
|
||||||
|
//console.log('fetch event', evt);
|
||||||
|
evt.respondWith(
|
||||||
|
caches.match(evt.request).then(cacheRes => {
|
||||||
|
return cacheRes || fetch(evt.request).then(fetchRes => {
|
||||||
|
return caches.open(dynamicCacheName).then(cache => {
|
||||||
|
cache.put(evt.request.url, fetchRes.clone()).then(r => {
|
||||||
|
return fetchRes;
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//Push notification, this is more of a demo you can test in the dev tool
|
||||||
|
self.addEventListener('push', evt => {
|
||||||
|
const title = "Test Notification";
|
||||||
|
const body = "Det her et en demo på hvordan en notification kan se ud! ";
|
||||||
|
const icon = "/icons/browserFavIcon.svg"
|
||||||
|
const tag = "simple-push-example-tag";
|
||||||
|
evt.waitUntil(
|
||||||
|
self.registration.showNotification(title, {
|
||||||
|
body : body,
|
||||||
|
icon : icon,
|
||||||
|
tag : tag
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function displayNotification(){
|
||||||
|
if(Notification.permission === 'granted'){
|
||||||
|
navigator.serviceWorker.getRegistration()
|
||||||
|
.then(function (reg){
|
||||||
|
reg.showNotification('Helloe ')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//Service Worker Registration
|
||||||
|
|
||||||
|
/*
|
||||||
|
Make sure that we support service worker :)
|
||||||
|
*/
|
||||||
|
|
||||||
|
if('serviceWorker' in navigator){
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
navigator.serviceWorker
|
||||||
|
.register('/js/serviceWorkerCachedWebpags.js')
|
||||||
|
.then(reg => console.log("Service Worker has been: registered"))
|
||||||
|
.catch(err => console.log(`Service Worker error: ${err}`))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Notification.requestPermission().then(function(permission){
|
||||||
|
console.log('Notification permission was:', permission)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if('caches' in window){
|
||||||
|
console.log("The browser supports caching ")
|
||||||
|
}else {
|
||||||
|
console.log("This browser is some junk, it dosen't support caching :(")
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
@extends("app.layout.base")
|
@extends("app.layout.base")
|
||||||
|
@section("title")
|
||||||
|
Home
|
||||||
|
@endsection
|
||||||
|
|
||||||
@section("content")
|
@section("content")
|
||||||
<style>
|
<style>
|
||||||
iframe, .ql-video {
|
iframe, .ql-video {
|
||||||
@@ -201,7 +205,7 @@
|
|||||||
</div>
|
</div>
|
||||||
@if($new->resource_id !== null)
|
@if($new->resource_id !== null)
|
||||||
<div class="header" style="background-size: cover; background-position: center; background-image: url('{{ asset(\App\Resource::query()->where("id", "=", $new->resource_id)->first()->filename) }}');"></div>
|
<div class="header" style="background-size: cover; background-position: center; background-image: url('{{ asset(\App\Resource::query()->where("id", "=", $new->resource_id)->first()->filename) }}');"></div>
|
||||||
<div class="information">{{__('msg.kategori')}}: {{\App\GuidesCategory::query()->where('id', '=', \App\Guide::query()->where('id','=', $new->arrangement_id)->first()->guide_category_id)->first()->guidesCategoryName}}</div>
|
<div class="information">{{__('msg.kategori')}} <span class="dot"></span> {{\App\GuidesCategory::query()->where('id', '=', \App\Guide::query()->where('id','=', $new->arrangement_id)->first()->guide_category_id)->first()->guidesCategoryName}}</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<div class="container" style="margin-top: 8px;">
|
<div class="container" style="margin-top: 8px;">
|
||||||
|
|||||||
Reference in New Issue
Block a user