start_url does not respond with a 200 when offline: The start_url did respond, but not via a service worker. Lighthouse Audit problem

我的未来我决定 提交于 2021-01-27 15:29:57

问题


I am creating a PWA that works offline with a service worker.

Right now it works correctly, but there is a problem in Lighthouse Audit.

When I run Lighthouse, in the PWA section I get this problem: start_url does not respond with a 200 when offline The start_url did respond, but not via a service worker.

How do I pass that audit, even if there are other audits that say that I have successfully installed a service worker?

My website is here: https://nariohtools.com and the service worker is here: https://nariohtools.com/sw.js

Thanks in advance.


回答1:


The related code is here:

caches.open(CACHE_NAME).then((cache) => {
  return fetch(evt.request)

You are opening the cache but you're not using the cached response and the request is forwarded to the network:

Use something like this instead:

caches.open(CACHE_NAME).then(cache => {
  return cache.match(evt.request).then(cacheResponse => cacheResponse || fetch(evt.request).then(networkResponse => {
  cache.put(evt.request, networkResponse.clone());
  return networkResponse;
}));


来源:https://stackoverflow.com/questions/64955146/start-url-does-not-respond-with-a-200-when-offline-the-start-url-did-respond-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!