我正在使用谷歌图表 google.load("可视化", "1", {packages:["corechart"]});
但是在检查网络使用情况时我发现加载时间很慢 format+en,default,corechart.I.js 加载大约需要 6 秒。任何解决方法来减少这个时间,为什么这个文件没有被缓存并且每次都从谷歌再次获取。
最佳答案
很遗憾,根据谷歌的服务条款,您无法合法地缓存/存储库。
Your users' computers must have access to https://www.google.com/jsapi in order to use the interactive features of Google Charts. This is because the visualization libraries that your page requires are loaded dynamically before you use them. The code for loading the appropriate library is part of the included jsapi script, and is called when you invoke the google.load() method. Our terms of service do not allow you to download the google.load or google.visualization code to use offline.
我建议尝试以下方法:
- 如果您在本地运行该应用,请尝试使用不同的互联网连接或更好的方式托管该应用,看看这是否会提高性能。它可能只是一个高延迟的互联网连接。
- 尝试在呈现图表的 View 之前找到加载库的位置。这可能是不可能的,但我想把它扔在那里。
如果您正在通过 CDN 加载其他 Assets 并且没有看到类似的问题,则可能是其他问题。如果是这种情况,我建议发布一些代码,以便我们了解您如何在您的应用中调用 API。
祝你好运。
关于javascript - 谷歌图表需要很长时间才能加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18998789/