forked from MapComplete/MapComplete
		
	Actually add caching to service worker
This commit is contained in:
		
							parent
							
								
									5f0ee916fd
								
							
						
					
					
						commit
						2247f004cc
					
				
					 1 changed files with 11 additions and 3 deletions
				
			
		| 
						 | 
					@ -46,9 +46,17 @@ self.addEventListener('fetch', (event) => {
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        event.respondWith(
 | 
					        event.respondWith(
 | 
				
			||||||
            caches.match(event.request).then(function (response) {
 | 
					            async () => {
 | 
				
			||||||
                return response || fetch(event.request);
 | 
					            const matched = caches.match(event.request)
 | 
				
			||||||
            }),
 | 
					                if(matched){
 | 
				
			||||||
 | 
					                    return matched
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                const response = fetch(event.request); 
 | 
				
			||||||
 | 
					                const cache = await caches.open(version);
 | 
				
			||||||
 | 
					                await cache.put(event.request.url, response);
 | 
				
			||||||
 | 
					                console.log("Put ",event.request.url,"into the cache")
 | 
				
			||||||
 | 
					                return response
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
        console.error("CRASH IN SW:", e)
 | 
					        console.error("CRASH IN SW:", e)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue