Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const CACHE_NAME = 'firstpwa-2';
- var urlsToCache = [
- '/',
- '/nav.html',
- '/index.html',
- '/pages/home.html',
- '/pages/bundesliga.html',
- '/css/materialize.min.css',
- '/js/materialize.min.js',
- '/js/script.js',
- '/js/api.js',
- '/images/2002.png',
- '/icon.png'
- ];
- self.addEventListener('install', function(event){
- event.waitUntil(
- caches.open(CACHE_NAME)
- .then(function(cache) {
- return cache.addAll(urlsToCache);
- })
- );
- })
- self.addEventListener('activate', function(event){
- event.waitUntil(
- caches.keys()
- .then(function(cacheNames) {
- return Promise.all(
- cacheNames.map(function(cacheName){
- if(cacheName != CACHE_NAME){
- console.log("ServiceWorker: cache " + cacheName + " dihapus");
- return caches.delete(cacheName);
- }
- })
- );
- })
- );
- })
- self.addEventListener("fetch", function(event){
- var base_url="https://api.football-data.org/"
- if (event.request.url.indexOf(base_url)> -1){
- event.respondWith(
- caches.open(CACHE_NAME).then(function(cache){
- return fetch(event.request).then(function(response){
- cache.put(event.request.url, response.clone());
- })
- })
- );
- }else{
- event.respondWith(
- caches.match(event.request, {ignoreSearch:true}).then(function(response){
- return response || fetch (event.request);
- })
- )
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement