获取事件:
self.addEventListener('fetch', function(event) {
console.log("[Service Worker] fetching "+event.request);
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});