-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
21 lines (21 loc) · 732 Bytes
/
sw.js
File metadata and controls
21 lines (21 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
if (location.hostname === 'localhost') {
const CACHE_NAME = 'cuberider';
self.addEventListener('fetch', function(event) {
if (event.request.url.startsWith('http://cube.crider.co.uk')) {
event.respondWith(
caches.match(event.request).then(function(response) {
// Cache hit - return response
if (response) return response;
// Cache not hit - needs fetching
return fetch(event.request).then(function(response) {
var responseToCache = response.clone();
caches.open(CACHE_NAME).then(function(cache) {
cache.put(event.request, responseToCache);
});
return response;
});
})
);
}
});
}