Slide 42
Slide 42 text
Handling Fetch Requests
42
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
sw.js
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(function(response) {
return response || fetch(event.request)
.then(res =>
caches.open(dataCacheName)
.then(function(cache) {
cache.put(event.request, res.clone());
return res;
})
);
})
);
});