脱机时,start_url不会以200进行响应:start_url确实进行了响应,但没有通过服务人员进行响应.灯塔审计问题 [英] start_url does not respond with a 200 when offline: The start_url did respond, but not via a service worker. Lighthouse Audit problem

查看:41
本文介绍了脱机时,start_url不会以200进行响应:start_url确实进行了响应,但没有通过服务人员进行响应.灯塔审计问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个与服务工作者脱机工作的PWA.

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

现在它可以正常工作,但是Lighthouse Audit中存在问题.

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

当我运行Lighthouse时,在PWA部分中出现了以下问题:脱机 start_url确实响应,但没有通过服务人员响应,start_url不会以200响应.

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.

即使有其他审核表明我已经成功安装了Service Worker,我如何通过该审核?

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

我的网站在这里: https://nariohtools.com ,服务人员在这里: https://nariohtools.com/sw.js

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

谢谢.

推荐答案

相关代码在这里:

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;
}));

这篇关于脱机时,start_url不会以200进行响应:start_url确实进行了响应,但没有通过服务人员进行响应.灯塔审计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆