我已经从 Create-React-App 库创建了一个示例应用程序。当我运行构建命令时,它会使用缓存优先策略自行生成一个服务工作线程。 但我需要更多的功能,比如缓存一些 API 响应。我不知道如何修改自动生成的服务 worker 中包含我自己的代码的脚本。 我找到了一些针对我的案例的帮助热线,但这些还不足以全面了解它。
By default, the generated service worker file will not intercept or cache any cross-origin traffic, like HTTP API requests, images, or embeds loaded from a different domain. If you would like to use a runtime caching strategy for those requests, you can eject and then configure the runtimeCaching option in the SWPrecacheWebpackPlugin section of webpack.config.prod.js.
以上文字来自官方doc
提前致谢!
最佳答案
我们最近在做一个项目时遇到了类似的问题,但我们不想“退出”。我们创建了一个小工具,允许您将自定义服务工作线程代码附加到 CRA 生成的代码中。
关于reactjs - 如何修改Create-React-App中自动生成的service-worker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46038668/