CSS不呈现在脱机方式使用服务的工作人员在铬

0

的问题

我想得到我的援工作的在线模式。 迄今为止,它的服务的所有文件从localhost,但CSS不渲染。 所有文件的要求从缓越来越状态200人。 (javascript和html是完全的功能),这里是我的服务的工作人员代码。

self.addEventListener("install", (event) => {
  event.waitUntil(
    caches.open("v1").then((cache) => {
      return cache.addAll([
        "list of assets",        
      ]);
    })
  );
});

self.addEventListener("fetch", function (event) {
  event.respondWith(
    caches.open("v1").then((cache) => {
      if (event.request.url == "http://localhost:3000/") {
        return cache
          .match("http://localhost:3000/index.html")
          .then((response) => {
            console.log({ response });
            return response;
          });
      } else {
        try {
          return cache.match(event.request).then((response) => {
            console.log(response);
            if (response != undefined) {
              console.log({ response: "Loading asset from cache." });
              return response;
            } else {
              let asset = fetch(event.request);
              cache.add(asset);
              return asset;
            }
          });
        } catch (error) {
          console.error(error);
        }
      }
    })
  );
});

1

最好的答案

0

你有没有尝试列出你的样式里,你有名单的资产'?

return cache.addAll([
    ‘./css/styles.css'
  ]);
2021-11-23 02:43:10

是的,它是存在的,并得到的状态,200当要求;我忘了说了,我也使用vite. 它只是发生在当地的主、正常工作的一个经常主机。
TK421

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................