angular - 如何使用 Service Worker 缓存图像?

标签 angular xmlhttprequest browser-cache service-worker

我是 Angular 世界的新手,我正在按照教程创建一个 PWA 应用程序。该应用程序在线时工作正常,但离线时无法加载图像并且看起来很糟糕。 我想缓存来自服务器的图像,以便当应用程序离线时,最近加载的图像会显示在应用程序中。 我很抱歉我的英语不好,感谢您对我的问题感兴趣。 我的应用程序链接:PWA app link

最佳答案

您可以在 Angular 中启用 ServiceWorker 来缓存图像。默认情况下,如果您将图像放在 assets 文件夹下,它们将被缓存。

Notice that all of the files the browser needs to render this application are cached. The ngsw-config.json boilerplate configuration is set up to cache the specific resources used by the CLI:

  • index.html
  • favicon.ico
  • Build artifacts (JS and CSS bundles)
  • Anything under assets.

引用:https://angular.io/guide/service-worker-getting-started#whats-being-cached

关于angular - 如何使用 Service Worker 缓存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49964172/

相关文章:

javascript - 自定义 XMLHttpRequest.prototype.open

javascript - 如何为 XmlHttpRequest 保留多组 cookie

angular - 在 IIS 上部署 Angular 7 应用程序后清除浏览器缓存

php - 利用浏览器缓存

javascript - 强制浏览器下载具有相同 src 的多个脚本标签

angular - 什么是 Angular 2 RC angular2-in-memory-web-api?

javascript - 在线时影响非 GET 请求的服务 worker - @angular/pwa

javascript - Angular2中组件属性变化的Observable

css - 更改 ion-datetime 值的颜色

excel - 如何从 Excel 宏 (vba) 使用 API 询问 ChatGPT?