@@ -31,24 +31,23 @@ const contentToCache = appShellFiles.concat(gamesImages);
31
31
// Installing Service Worker
32
32
self . addEventListener ( 'install' , ( e ) => {
33
33
console . log ( '[Service Worker] Install' ) ;
34
- e . waitUntil (
35
- caches . open ( cacheName ) . then ( ( cache ) => {
36
- console . log ( '[Service Worker] Caching all: app shell and content' ) ;
37
- return cache . addAll ( contentToCache ) ;
38
- } ) ,
39
- ) ;
34
+ e . waitUntil ( ( async ( ) => {
35
+ const cache = await caches . open ( cacheName ) ;
36
+ console . log ( '[Service Worker] Caching all: app shell and content' ) ;
37
+ await cache . addAll ( contentToCache ) ;
38
+ } ) ( ) ) ;
40
39
} ) ;
41
40
42
41
// Fetching content using Service Worker
43
42
self . addEventListener ( 'fetch' , ( e ) => {
44
- e . respondWith (
45
- caches . match ( e . request ) . then ( ( r ) => {
46
- console . log ( `[Service Worker] Fetching resource: ${ e . request . url } ` ) ;
47
- return r || fetch ( e . request ) . then ( ( response ) => caches . open ( cacheName ) . then ( ( cache ) => {
48
- console . log ( `[Service Worker] Caching new resource: ${ e . request . url } ` ) ;
49
- cache . put ( e . request , response . clone ( ) ) ;
50
- return response ;
51
- } ) ) ;
52
- } ) ,
53
- ) ;
43
+ e . respondWith ( ( async ( ) => {
44
+ const r = await caches . match ( e . request ) ;
45
+ console . log ( `[Service Worker] Fetching resource: ${ e . request . url } ` ) ;
46
+ if ( r ) return r ;
47
+ const response = await fetch ( e . request ) ;
48
+ const cache = await caches . open ( cacheName ) ;
49
+ console . log ( `[Service Worker] Caching new resource: ${ e . request . url } ` ) ;
50
+ cache . put ( e . request , response . clone ( ) ) ;
51
+ return response ;
52
+ } ) ( ) ) ;
54
53
} ) ;
0 commit comments