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:
co-authored by
Claude Opus 4.5
parent
6d3d76982a
commit
b345826566
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user