gpt4 book ai didi

reactjs - 在 Firebase : New deployment not showing (old deployment cached in browser) 上 react 应用

转载 作者:行者123 更新时间:2023-12-03 22:31:33 25 4
gpt4 key购买 nike

我使用 create-react-app 创建了一个 React 应用程序并将其部署到 Firebase,如下所示:
npm run build && firebase deploy
它部署得很好。
问题是在部署之后,应用程序的先前版本继续显示在浏览器上 - 就好像浏览器正在缓存整个应用程序一样。

我看到了关于这个问题的帖子:
https://github.com/facebook/create-react-app/issues/1910

我真的需要重置浏览器上的缓存才能获得新版本的应用程序。
有没有办法使用 React 应用程序或 Firebase 控制台禁用应用程序的浏览器缓存,或者至少确保显示最新的部署?

最佳答案

我在这里找到了我的问题的答案:

https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#opting-out-of-caching

该问题特定于 React.js 而不是 Firebase。

Opting Out of Caching If you would prefer not to enable service workers prior to your initial production deployment, then remove the call to registerServiceWorker() from src/index.js.

If you had previously enabled service workers in your production deployment and have decided that you would like to disable them for all your existing users, you can swap out the call to registerServiceWorker() in src/index.js first by modifying the service worker import:

import { unregister } from './registerServiceWorker'; and then call unregister() instead. After the user visits a page that has unregister(), the service worker will be uninstalled. Note that depending on how /service-worker.js is served, it may take up to 24 hours for the cache to be invalidated.

关于reactjs - 在 Firebase : New deployment not showing (old deployment cached in browser) 上 react 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50598614/

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