关于reactjs:React service worker 添加文件到缓存 | 珊瑚贝

React service worker add files to cache


基于 create-react-app 构建第一个 React 应用。它已经在生产版本中有一个 service-worker.js,但我需要手动添加几个 JavaScript(workers)文件。这些文件不包含在 HTML 中,服务工作者不会缓存它们。

将文件添加到服务工作者缓存列表的正确方法是什么?

  • 你在使用 create-react-app 吗?
  • 是的,我正在使用 create-react-app


因为没有找到更好的解决方案,我决定修改文件node_modules/react-scripts/config/webpack.config.prod.js

找线

1
new SWPrecacheWebpackPlugin({

并粘贴在下面

1
2
3
mergeStaticsConfig: true,
stripPrefix: ‘./public/’,
staticFileGlobs: [‘./public/./js/jimp.min.js’, ‘./public/./js/jimp-worker.js’],

  • 这被认为是一种不好的做法,请查看以下答案


来源:https://www.codenong.com/51797180/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8956.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?