@@ -11,19 +11,14 @@ const cacheName = `${cacheNamePrefix}${self.assetsManifest.version}`;
1111const offlineAssetsInclude = [ / \. d l l $ / , / \. p d b $ / , / \. w a s m / , / \. h t m l / , / \. j s $ / , / \. j s o n $ / , / \. c s s $ / , / \. w o f f $ / , / \. p n g $ / , / \. j p e ? g $ / , / \. g i f $ / , / \. i c o $ / , / \. b l a t $ / , / \. d a t $ / ] ;
1212const offlineAssetsExclude = [ / ^ s e r v i c e - w o r k e r \. j s $ / ] ;
1313
14- // Replace with your base path if you are hosting on a subfolder. Ensure there is a trailing '/'.
15- const base = "/" ;
16- const baseUrl = new URL ( base , self . origin ) ;
17- const manifestUrlList = self . assetsManifest . assets . map ( asset => new URL ( asset . url , baseUrl ) . href ) ;
18-
1914async function onInstall ( event ) {
2015 console . info ( 'Service worker: Install' ) ;
2116
2217 // Fetch and cache all matching items from the assets manifest
2318 const assetsRequests = self . assetsManifest . assets
2419 . filter ( asset => offlineAssetsInclude . some ( pattern => pattern . test ( asset . url ) ) )
2520 . filter ( asset => ! offlineAssetsExclude . some ( pattern => pattern . test ( asset . url ) ) )
26- . map ( asset => new Request ( asset . url , { integrity : asset . hash , cache : 'no-cache' } ) ) ;
21+ . map ( asset => new Request ( asset . url , { integrity : asset . hash } ) ) ;
2722 await caches . open ( cacheName ) . then ( cache => cache . addAll ( assetsRequests ) ) ;
2823}
2924
@@ -40,10 +35,9 @@ async function onActivate(event) {
4035async function onFetch ( event ) {
4136 let cachedResponse = null ;
4237 if ( event . request . method === 'GET' ) {
43- // For all navigation requests, try to serve index.html from cache,
44- // unless that request is for an offline resource.
38+ // For all navigation requests, try to serve index.html from cache
4539 // If you need some URLs to be server-rendered, edit the following check to exclude those URLs
46- const shouldServeIndexHtml = event . request . mode === 'navigate' && ! manifestUrlList . some ( url => url === event . request . url ) ;
40+ const shouldServeIndexHtml = event . request . mode === 'navigate' ;
4741
4842 const request = shouldServeIndexHtml ? 'index.html' : event . request ;
4943 const cache = await caches . open ( cacheName ) ;
0 commit comments