fix service worker cache bugs
This commit is contained in:
		
							parent
							
								
									8f24531d94
								
							
						
					
					
						commit
						f56f746477
					
				
					 1 changed files with 12 additions and 12 deletions
				
			
		| 
						 | 
					@ -15,8 +15,6 @@ const webpackAssets = __shell__
 | 
				
			||||||
  .filter(filename => !filename.endsWith('.map'))
 | 
					  .filter(filename => !filename.endsWith('.map'))
 | 
				
			||||||
  .filter(filename => filename !== '/index.html')
 | 
					  .filter(filename => filename !== '/index.html')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const cacheSet = new Set([].concat(assets).concat(webpackAssets))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// `routes` is an array of `{ pattern: RegExp }` objects that
 | 
					// `routes` is an array of `{ pattern: RegExp }` objects that
 | 
				
			||||||
// match the pages in your app
 | 
					// match the pages in your app
 | 
				
			||||||
const routes = __routes__
 | 
					const routes = __routes__
 | 
				
			||||||
| 
						 | 
					@ -81,16 +79,18 @@ self.addEventListener('fetch', event => {
 | 
				
			||||||
  event.respondWith((async () => {
 | 
					  event.respondWith((async () => {
 | 
				
			||||||
    let sameOrigin = url.origin === self.origin
 | 
					    let sameOrigin = url.origin === self.origin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // always serve webpack-generated resources and
 | 
					    if (sameOrigin) {
 | 
				
			||||||
    // assets from the cache
 | 
					      // always serve webpack-generated resources and
 | 
				
			||||||
    if (sameOrigin && cacheSet.has(url.pathname)) {
 | 
					      // assets from the cache if possible
 | 
				
			||||||
      return caches.match(req)
 | 
					      let response = await caches.match(req)
 | 
				
			||||||
    }
 | 
					      if (response) {
 | 
				
			||||||
 | 
					        return response
 | 
				
			||||||
    // for routes, serve the /index.html file from the most recent
 | 
					      }
 | 
				
			||||||
    // assets cache
 | 
					      // for routes, serve the /index.html file from the most recent
 | 
				
			||||||
    if (sameOrigin && routes.find(route => route.pattern.test(url.pathname))) {
 | 
					      // assets cache
 | 
				
			||||||
      return caches.match('/index.html')
 | 
					      if (routes.find(route => route.pattern.test(url.pathname))) {
 | 
				
			||||||
 | 
					        return caches.match('/index.html')
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // For these GET requests, go cache-first
 | 
					    // For these GET requests, go cache-first
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue