如何停止警告:看起来您正在使用Firebase JS SDK的开发版本?

时间:2018-06-13 09:45:23

标签: javascript firebase

It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.

For the CDN builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):

https://www.gstatic.com/firebasejs/5.0.0/firebase-<PACKAGE>.js

它占用了我已经有限的控制台空间的一半:(

注意:我在html中使用firebase ..使用脚本标记。我没有使用导入语法,如下所述:similar question

如何停止此警告?

3 个答案:

答案 0 :(得分:11)

要更清楚地回答这个问题,

您最可能拥有的是

<script src="https://www.gstatic.com/firebasejs/6.0.2/firebase.js"></script>

因为这是Firebase从“将Firebase添加到您的Web应用程序”屏幕中为您提供的。

但是,这是在导入所有Firebase模块。我不知道为什么Firebase将此作为生成的脚本,但是您要做的就是将-app添加到源中,现在就可以了。

<script src="https://www.gstatic.com/firebasejs/6.0.2/firebase-app.js"></script>

然后,要使用Firebase的每个后续功能,您将需要添加另一脚本行。例如,如果您想将云消息传递添加到您的Web应用程序,则仅需要这样做。

<script src="https://www.gstatic.com/firebasejs/6.0.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.0.2/firebase-messaging.js"></script>

您可以找到更多信息,包括完整的进口清单here from Firebase.

答案 1 :(得分:2)

您的错误消息告诉您如何修复它...此部分就在这里:

For the CDN builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):

https://www.gstatic.com/firebasejs/5.0.0/firebase-<PACKAGE>.js

因此,如果您使用的是Firebase身份验证,则会有一个请求https://www.gstatic.com/firebasejs/5.0.0/firebase-auth.js的脚本标记...而对于Firebase数据库,您还会有另一个带有https://www.gstatic.com/firebasejs/5.0.0/firebase-database.js的脚本标记。 ...只需遵循您需要的Firebase的任何其他部分的模式。

答案 2 :(得分:0)

here给出的细节不是很容易理解:

步骤1:删除下面一行,因为它是开发版本:

<script src="https://www.gstatic.com/firebasejs/5.8.6/firebase.js"></script>

第2步:添加以下行(必需),生产版本:

<script src="https://www.gstatic.com/firebasejs/5.8.6/firebase-app.js"></script>

第3步:添加所需的其他软件包/服务,例如数据库(可选),生产版本:

<script src="https://www.gstatic.com/firebasejs/5.8.6/firebase-database.js"></script>

这解决了问题。