我可以在全球以外的其他地方注入 google AJAX API 自动加载吗?

发布于 2024-09-27 01:29:10 字数 949 浏览 8 评论 0原文

我正在努力解决这个问题。我知道谷歌可视化地理地图的自动加载必须位于您的文档的一部分中。

问题是每次我在应用程序中重新加载其他一些页面时,谷歌都会重新加载所有内容,而我想将其删除。因此,我尝试将 :

<script type="text/javascript" src="http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22packages%22%3A%5B%22geomap%22%2C%22table%22%5D%7D%5D%7D"></script>

从全局模板中取出,并在页面调用发生时注入它。因此,仅在需要时才加载 google API,以便将加载时间保持在绝对低的水平。我想知道这是否可行,以及谷歌自动加载是否必须始终存在于全局中。

我正在使用 Prototype Javascript 框架,这是我注入自动加载的代码:

var element = new Element('script', {
    src: "http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22packages%22%3A%5B%22geomap%22%2C%22table%22%5D%7D%5D%7D",
    type: 'text/javascript'
});

$$('head')[0].appendChild(element);

这使其远离网站的其余部分,但根本不起作用。我是否认为这是错误的,或者我是否有可能只在一个地方加载 API,而不是在所有地方加载 API。

谢谢

There is this issue I am struggling with. I know that the autoload for the google visualization geomap must be in the part of your document.

The thing is every time I reload some other pages in my application the google reloads everything and this I want to take out. So I tried taking the :

<script type="text/javascript" src="http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22packages%22%3A%5B%22geomap%22%2C%22table%22%5D%7D%5D%7D"></script>

out of my global template and inject it when the page call happens. So to only load the google API when I need it so to keep loading times to an absolute low. I want to know if this is do-able and if the google autoload MUST exist in the global at all times.

I am using Prototype Javascript framework and here is my code to inject the autoload :

var element = new Element('script', {
    src: "http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22packages%22%3A%5B%22geomap%22%2C%22table%22%5D%7D%5D%7D",
    type: 'text/javascript'
});

$('head')[0].appendChild(element);

This keeps it out of the rest of the site but doesn't work at all. Am I thinking about this wrong or is there some possibility of me only loading the API in one place and not everywhere.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

來不及說愛妳 2024-10-04 01:29:10

看起来如果您在正在使用的视图模板中执行此操作,则效果很好。每次呈现模板时,它都会刷新页面,从而加载 Google API 代码。

It seems like if you do it in the template of the view you are using it works fine. Every time the template gets rendered it refreshes the page resulting in the Google API code loading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文