refactor: Simplify prefetch by moving to activate event

Remove message-based prefetch in favor of prefetching on activate:
- Remove PREFETCH_ASSETS message listener from service worker
- Remove prefetchAssets() call and idle callback from pushHelper.js
- Call prefetchAssets() directly in activate event

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Pranav
2026-01-10 21:14:35 -08:00
co-authored by Claude Opus 4.5
parent 6d3d76982a
commit b345826566
2 changed files with 1 additions and 28 deletions
@@ -2,13 +2,6 @@ import NotificationSubscriptions from '../api/notificationSubscription';
import auth from '../api/auth';
import { useAlert } from 'dashboard/composables';
/**
* Request the service worker to prefetch all assets in the manifest.
*/
const prefetchAssets = () => {
navigator.serviceWorker?.controller?.postMessage({ type: 'PREFETCH_ASSETS' });
};
export const verifyServiceWorkerExistence = (callback = () => {}) => {
if (!('serviceWorker' in navigator)) {
// Service Worker isn't supported on this browser, disable or hide UI.
@@ -41,14 +34,6 @@ export const verifyServiceWorkerExistence = (callback = () => {}) => {
});
});
// Trigger asset prefetch during idle time
if ('requestIdleCallback' in window) {
window.requestIdleCallback(() => prefetchAssets(), { timeout: 5000 });
} else {
// Fallback: prefetch after 3 seconds
setTimeout(prefetchAssets, 3000);
}
callback(registration);
})
.catch(registrationError => {
+1 -13
View File
@@ -122,12 +122,7 @@ self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', event => {
event.waitUntil(
Promise.all([
// Clean up stale assets not in current manifest
cleanupStaleAssets(),
// Take control of all clients
self.clients.claim(),
])
Promise.all([cleanupStaleAssets(), prefetchAssets(), self.clients.claim()])
);
});
@@ -164,10 +159,3 @@ async function cleanupStaleAssets() {
await Promise.all(deletions);
}
self.addEventListener('message', async event => {
if (event.data?.type === 'PREFETCH_ASSETS') {
await prefetchAssets();
event.ports[0]?.postMessage({ type: 'PREFETCH_COMPLETE' });
}
});