我是 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/