fix bug and version check
Some checks failed
Deploy MyApp on Same Server / build-and-deploy (push) Failing after 1s
Some checks failed
Deploy MyApp on Same Server / build-and-deploy (push) Failing after 1s
This commit is contained in:
21
public/sw.js
21
public/sw.js
@@ -1,5 +1,5 @@
|
||||
const CACHE_NAME = 'greenhome-v2';
|
||||
const STATIC_CACHE_NAME = 'greenhome-static-v2';
|
||||
const CACHE_NAME = 'greenhome-1766074058129';
|
||||
const STATIC_CACHE_NAME = 'greenhome-static-1766074058129';
|
||||
|
||||
// Static assets to cache on install
|
||||
const STATIC_FILES_TO_CACHE = [
|
||||
@@ -32,7 +32,8 @@ self.addEventListener('install', (event) => {
|
||||
} catch (error) {
|
||||
console.log('Some static files failed to cache:', error);
|
||||
}
|
||||
await self.skipWaiting();
|
||||
// Don't skip waiting automatically - let user decide when to update
|
||||
// await self.skipWaiting();
|
||||
})()
|
||||
);
|
||||
});
|
||||
@@ -53,6 +54,20 @@ self.addEventListener('activate', (event) => {
|
||||
);
|
||||
});
|
||||
|
||||
// Listen for messages from clients (e.g., when user clicks update button)
|
||||
self.addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'SKIP_WAITING') {
|
||||
self.skipWaiting().then(() => {
|
||||
// Notify all clients about update
|
||||
return self.clients.matchAll();
|
||||
}).then((clients) => {
|
||||
clients.forEach((client) => {
|
||||
client.postMessage({ type: 'SW_UPDATED' });
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const { request } = event;
|
||||
const url = new URL(request.url);
|
||||
|
||||
3
public/version.json
Normal file
3
public/version.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"version": "1766074058129"
|
||||
}
|
||||
Reference in New Issue
Block a user