As maravilhas do service worker142. NO EVENT INSTALL DO SERVICE WORKER
sw.js
self.addEventListener('install', event => {
event.waitUntil(
caches.open('phpeste-v1').then(function(response) {
return cache.addAll([ ... ]);
})
);
});
148. REMOVE TODOS OS CACHES, QUE COMEÇAM COM PHPESTE-
E QUE NÃO SEJA O PHPESTE-V1
caches.keys().then(function(cacheNames)
{ cacheNames.filter(function(cacheName) {
return cacheName.startsWith('phpeste-')
&& cacheName != 'phpeste-v1';
}).map(function(cacheName) {
return caches.delete(cacheName);
});
})
157. self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
DE BUSCA DE CADA REQUEST
161. self.addEventListener('install', function(event) {
event.waitUntil(
caches.open('phpeste-v1').then(function(cache) {
return cache.addAll([
'./',
'https://fonts.googleapis.com/css?family=Ro...',
'vendor/bootstrap/bootstrap.min.css’...,
'/phpeste/manifest.json' ...,
'vendor/angular/angular.min.js' ...,
'assets/img/b_1024.jpg ', 'img/b_2048.jpg ',
'api/sessions',
'api/speakers',
'api/schedule',
]);
})
);
});
162. self.addEventListener('install', function(event) {
event.waitUntil(
caches.open('phpeste-v1').then(function(cache) {
return cache.addAll([
'./',
'https://fonts.googleapis.com/css?family=Ro...',
'vendor/bootstrap/bootstrap.min.css’...,
'/phpeste/manifest.json' ...,
'vendor/angular/angular.min.js' ...,
'assets/img/b_1024.jpg ', 'img/b_2048.jpg ',
'api/sessions',
'api/speakers',
'api/schedule',
]);
})
);
});
QUANDO INSTALAR
O SERVICE WORKER
163. self.addEventListener('install', function(event) {
event.waitUntil(
caches.open('phpeste-v1').then(function(cache) {
return cache.addAll([
'./',
'https://fonts.googleapis.com/css?family=Ro...',
'vendor/bootstrap/bootstrap.min.css’...,
'/phpeste/manifest.json' ...,
'vendor/angular/angular.min.js' ...,
'assets/img/b_1024.jpg ', 'img/b_2048.jpg ',
'api/sessions',
'api/speakers',
'api/schedule',
]);
})
);
});
ADICIONO OS ARQUIVOS ESTATICOS
NO CACHE
164. self.addEventListener('install', function(event) {
event.waitUntil(
caches.open('phpeste-v1').then(function(cache) {
return cache.addAll([
'./',
'https://fonts.googleapis.com/css?family=Ro...',
'vendor/bootstrap/bootstrap.min.css’...,
'/phpeste/manifest.json' ...,
'vendor/angular/angular.min.js' ...,
'assets/img/b_1024.jpg ', 'img/b_2048.jpg ',
'api/sessions',
'api/speakers',
'api/schedule',
]);
})
);
});
ISSO NÃO DEVERIA ESTAR AQUI,
MAS É SÓ COMO EXEMPLO