是否可以告诉浏览器提前启动ServiceWorker激活和安装阶段?
当我查看我们在Chrome中的性能时,您可以在下面看到,工作程序在前1.5秒内加载,但激活不是在3.3秒之前!有没有办法告诉浏览器尽快安装和激活ServiceWorker?
这是我的ServiceWorker代码:
self.addEventListener('install', (event) => {
// Bypass the waiting lifecycle stage,
// Just in case there's an older version of this SW registration.
event.waitUntil(self.skipWaiting());
});
self.addEventListener('activate', (event) => {
// Take control of all pages under this SW's scope immediately,
// Instead of waiting for reload/navigation.
event.waitUntil(self.clients.claim());
});