Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
m2-starter-repo/sw.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (25 sloc)
774 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name of our cache | |
const cacheName = 'offline-pwa-gallery-v1'; | |
// URLs to cache for offline mode | |
const urlsToCache = [ | |
]; | |
// Cache files on service worker registration | |
self.addEventListener('install', (event) => { | |
event.waitUntil( | |
caches.open(cacheName).then((cache) => { | |
return cache.addAll(urlsToCache); | |
}) | |
); | |
}); | |
// Intercept fetch requests to serve cached assets | |
self.addEventListener('fetch', (event) => { | |
if(event.request.url.match(/^https:\/\//)){ | |
console.log('Browser is requesting:', event.request.url); | |
} | |
event.respondWith( | |
caches.match(event.request).then((cachedResponse) => { | |
// It can update the cache to serve updated content on the next request | |
return cachedResponse || fetch(event.request); | |
}) | |
); | |
}); |