@@ -13,7 +13,11 @@ const APP_SHELL = [
1313
1414self . addEventListener ( 'install' , ( event ) => {
1515 event . waitUntil (
16- caches . open ( CACHE_NAME ) . then ( ( cache ) => cache . addAll ( APP_SHELL ) )
16+ caches . open ( CACHE_NAME ) . then ( ( cache ) =>
17+ Promise . all ( APP_SHELL . map ( ( url ) =>
18+ fetch ( url , { cache : 'reload' } ) . then ( ( resp ) => cache . put ( url , resp ) )
19+ ) )
20+ )
1721 ) ;
1822 self . skipWaiting ( ) ;
1923} ) ;
@@ -51,12 +55,6 @@ self.addEventListener('fetch', (event) => {
5155 return ;
5256 }
5357
54- // nocache=1 in URL: bypass all caches and fetch from network
55- if ( url . searchParams . get ( 'nocache' ) === '1' ) {
56- event . respondWith ( fetch ( event . request , { cache : 'no-store' } ) ) ;
57- return ;
58- }
59-
6058 // Skip demo.note — large and not essential for offline
6159 if ( url . pathname . endsWith ( 'demo.note' ) ) return ;
6260
@@ -74,8 +72,14 @@ self.addEventListener('fetch', (event) => {
7472 return ;
7573 }
7674
77- // Local assets: cache -first, fall back to network
75+ // Local assets: network -first, fall back to cache (ensures fresh deploys)
7876 event . respondWith (
79- caches . match ( event . request ) . then ( ( cached ) => cached || fetch ( event . request ) )
77+ fetch ( event . request )
78+ . then ( ( response ) => {
79+ const clone = response . clone ( ) ;
80+ caches . open ( CACHE_NAME ) . then ( ( cache ) => cache . put ( event . request , clone ) ) ;
81+ return response ;
82+ } )
83+ . catch ( ( ) => caches . match ( event . request ) )
8084 ) ;
8185} ) ;
0 commit comments