File tree Expand file tree Collapse file tree
cloud/src/LrmCloud.Web/wwwroot Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -266,12 +266,21 @@ window.lrmServiceWorker = {
266266 }
267267 } ,
268268
269- applyUpdate : function ( ) {
269+ applyUpdate : async function ( ) {
270+ // Clear all caches to ensure fresh load (prevents stale DLL issues)
271+ try {
272+ const cacheNames = await caches . keys ( ) ;
273+ await Promise . all ( cacheNames . map ( name => caches . delete ( name ) ) ) ;
274+ console . log ( '[SW] Caches cleared for update' ) ;
275+ } catch ( err ) {
276+ console . error ( '[SW] Failed to clear caches:' , err ) ;
277+ }
278+
270279 if ( this . registration ?. waiting ) {
271280 this . registration . waiting . postMessage ( { type : 'SKIP_WAITING' } ) ;
272- // Fallback reload in case controllerchange doesn't fire
273- setTimeout ( ( ) => window . location . reload ( ) , 1000 ) ;
274281 }
282+ // Reload after cache clear (controllerchange may also trigger reload)
283+ window . location . reload ( ) ;
275284 }
276285} ;
277286
Original file line number Diff line number Diff line change @@ -102,12 +102,29 @@ self.addEventListener('fetch', (event) => {
102102 return ;
103103 }
104104
105+ // For Blazor framework files - NETWORK FIRST (critical for version consistency)
106+ // Blazor uses integrity hashes; serving stale DLLs causes hash mismatch errors
107+ if ( url . pathname . includes ( '/_framework/' ) ) {
108+ event . respondWith (
109+ fetch ( request )
110+ . then ( ( response ) => {
111+ if ( response . ok ) {
112+ const responseClone = response . clone ( ) ;
113+ caches . open ( CACHE_NAME )
114+ . then ( ( cache ) => cache . put ( request , responseClone ) ) ;
115+ }
116+ return response ;
117+ } )
118+ . catch ( ( ) => caches . match ( request ) ) // Fallback to cache only if offline
119+ ) ;
120+ return ;
121+ }
122+
105123 // For static assets, try cache first, then network
106124 if (
107125 url . pathname . includes ( '/css/' ) ||
108126 url . pathname . includes ( '/js/' ) ||
109127 url . pathname . includes ( '/_content/' ) ||
110- url . pathname . includes ( '/_framework/' ) ||
111128 url . pathname . endsWith ( '.png' ) ||
112129 url . pathname . endsWith ( '.ico' ) ||
113130 url . pathname . endsWith ( '.json' ) ||
You can’t perform that action at this time.
0 commit comments