@@ -28,19 +28,23 @@ self.addEventListener('fetch', (event) => {
2828
2929function refresh ( cache , event , oldResponse ) {
3030 fetch ( event . request ) . then ( ( response ) => {
31- cache . put ( event . request . url , response . clone ( ) ) ;
31+ if ( response . ok ) {
32+ cache . put ( event . request . url , response . clone ( ) ) ;
3233
33- return Promise . all ( [ response . text ( ) , oldResponse . text ( ) ] ) . then ( ( [ r1 , r2 ] ) => {
34- if ( r1 === r2 )
35- console . log ( "Cache reloaded, nothing changed" ) ;
36- else {
37- console . log ( "Cache reloaded, publishing changes" ) ;
38- clients . matchAll ( ) . then ( ( clients ) => {
39- for ( const client of clients )
40- client . postMessage ( "bb-refresh" ) ;
41- } ) ;
42- }
43- } ) ;
34+ return Promise . all ( [ response . text ( ) , oldResponse . text ( ) ] ) . then ( ( [ r1 , r2 ] ) => {
35+ if ( r1 === r2 )
36+ console . log ( "Cache reloaded, nothing changed" ) ;
37+ else {
38+ console . log ( "Cache reloaded, publishing changes" ) ;
39+ clients . matchAll ( ) . then ( ( clients ) => {
40+ for ( const client of clients )
41+ client . postMessage ( "bb-refresh" ) ;
42+ } ) ;
43+ }
44+ } ) ;
45+ } else {
46+ console . log ( `Cache reloading failed, status ${ response . status } ` ) ;
47+ }
4448 } ) . catch ( ( err ) => {
4549 console . warn ( "Cache reloading failed" , err . stack || err ) ;
4650 } )
0 commit comments