fix Saldo when press refuse coins.
fix Risolvere problema del ritardo quando si fa il primo login...
This commit is contained in:
@@ -10,19 +10,21 @@ import {
|
||||
CacheFirst,
|
||||
} from 'workbox-strategies'
|
||||
|
||||
const ENABLE_DYNAMIC_CACHING = false;
|
||||
|
||||
// Used for filtering matches based on status code, header, or both
|
||||
import { CacheableResponsePlugin } from 'workbox-cacheable-response'
|
||||
// Used to limit entries in cache, remove entries after a certain period of time
|
||||
import { ExpirationPlugin } from 'workbox-expiration'
|
||||
|
||||
console.log(
|
||||
' [ VER-0.5.1 ] _---------________------ PAO: this is my custom service worker')
|
||||
' [ VER-0.5.4 ] _---------________------ PAO: this is my custom service worker')
|
||||
|
||||
importScripts('js/idb.js')
|
||||
importScripts('js/storage.js')
|
||||
// importScripts('js/workbox-sw.js')
|
||||
importScripts('js/workbox-sw.js')
|
||||
|
||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.4/workbox-sw.js');
|
||||
// importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.4/workbox-sw.js');
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +36,7 @@ let port = 3000
|
||||
if (self.location.hostname.startsWith('test')) {
|
||||
port = 3001
|
||||
}
|
||||
console.log('SW-06 1')
|
||||
console.log('SW- app ver 0.5.4')
|
||||
|
||||
const cfgenv = {
|
||||
serverweb: `${self.location.protocol}//${self.location.hostname}:${port}`,
|
||||
@@ -126,6 +128,7 @@ if (workbox) {
|
||||
}),
|
||||
)
|
||||
|
||||
/*
|
||||
// Per Articoli....
|
||||
const articleHandler = new NetworkFirst({
|
||||
cacheName: 'articles-cache',
|
||||
@@ -142,7 +145,7 @@ if (workbox) {
|
||||
|
||||
registerRoute(
|
||||
new RegExp(/(.*)article(.*)\.html/), args => articleHandler.handle(args),
|
||||
)
|
||||
) */
|
||||
|
||||
registerRoute(
|
||||
new RegExp(/.*(?:googleapis|gstatic)\.com.*$/),
|
||||
@@ -259,6 +262,7 @@ if (workbox) {
|
||||
return fetch(args.event.request)
|
||||
.then((res) => caches.open('dynamic')
|
||||
.then((cache) => {
|
||||
console.log('fetch cache')
|
||||
console.log('cache', args.event.request.url)
|
||||
cache.put(args.event.request.url, res.clone())
|
||||
return res
|
||||
@@ -352,13 +356,15 @@ if ('serviceWorker' in navigator) {
|
||||
|
||||
}
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
/* self.addEventListener('fetch', (event) => {
|
||||
if (event.request.url === '/') {
|
||||
const StaleWhileRevalidate = new StaleWhileRevalidate();
|
||||
event.respondWith(StaleWhileRevalidate.handle({ event }));
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
console.log('[Service Worker] Fetching something ....', event);
|
||||
console.log('event.request.cache=', event.request.cache)
|
||||
@@ -366,7 +372,26 @@ self.addEventListener('fetch', function (event) {
|
||||
console.log('SAME ORIGIN!', event);
|
||||
return;
|
||||
}
|
||||
event.respondWith(caches.match(event.request));
|
||||
event.respondWith((async () => {
|
||||
const cachedResponse = await caches.match(event.request);
|
||||
if (cachedResponse) {
|
||||
return cachedResponse;
|
||||
}
|
||||
|
||||
const response = await fetch(event.request);
|
||||
|
||||
if (!response || response.status !== 200 || response.type !== 'basic') {
|
||||
return response;
|
||||
}
|
||||
|
||||
if (ENABLE_DYNAMIC_CACHING) {
|
||||
const responseToCache = response.clone();
|
||||
const cache = await caches.open(DYNAMIC_CACHE)
|
||||
await cache.put(event.request, response.clone());
|
||||
}
|
||||
|
||||
return response;
|
||||
})());
|
||||
});
|
||||
|
||||
|
||||
@@ -384,6 +409,7 @@ self.addEventListener('message', event => {
|
||||
console.log(event.data)
|
||||
})
|
||||
|
||||
|
||||
addEventListener('fetch', event => {
|
||||
// Prevent the default, and handle the request ourselves.
|
||||
event.respondWith(async function() {
|
||||
@@ -398,19 +424,7 @@ addEventListener('fetch', event => {
|
||||
}());
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
event.respondWith(
|
||||
caches.match(event.request).then(function (response) {
|
||||
return response ||
|
||||
fetch(event.request, event.headers)
|
||||
.catch(err => {
|
||||
console.log('_______________________ ERRORE FETCH SW: ', event.request, err)
|
||||
writeData('config', { _id: 2, stateconn: 'offline' })
|
||||
return caches.match(event.request);
|
||||
})
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
event.respondWith(
|
||||
@@ -423,6 +437,7 @@ self.addEventListener('fetch', function (event) {
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
self.addEventListener('sync', function (event) {
|
||||
console.log('[Service Worker V5] Background syncing', event);
|
||||
console.log('event:', event);
|
||||
|
||||
Reference in New Issue
Block a user