gpt4 book ai didi

javascript - ServiceWorker 不加载图像

转载 作者:行者123 更新时间:2023-11-30 09:39:02 29 4
gpt4 key购买 nike

我致力于将 [Service Worker 技术] 实现到网站中。

图像 外,一切都按预期工作。

图像根本没有加载。

我想知道这是否是预期的行为,或者是否应该加载图像。

为了重现此错误,我全新安装了 Polymer Starter Kit 并在第一个 View 中添加了一行 my-view1.html

<img src="../images/cat.png" alt="">

我将图像添加到相应目录。

如果您继续并禁用您的 wifi,您会看到该页面仍在按预期加载。只有猫图片不会加载。

我正在使用:

  • Polymer-CLI v0.17.0
  • Ubuntu v16.04
  • 节点 v4.2.6
  • npm v3.5.2

问题

Images 应该用 Service Worker 加载吗?如果是,我做错了什么?

最佳答案

sw-precache-config.js 中,只需添加要缓存的文件即可:

module.exports = {
staticFileGlobs: [
'/index.html',
'/manifest.json',
'/bower_components/webcomponentsjs/webcomponents-lite.min.js',
],
navigateFallback: 'index.html',
};

目前只有index.html, manifest.json, webcomponents-lite.min.js 被注册到缓存服务人员。

module.exports = {
staticFileGlobs: [
'/index.html',
'/manifest.json',
'/images/mycat.png',
'/bower_components/webcomponentsjs/webcomponents-lite.min.js',
],
navigateFallback: 'index.html',
};

关于javascript - ServiceWorker 不加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42101643/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com