Google Api Feed - 多请求

发布于 2024-09-17 21:36:57 字数 535 浏览 0 评论 0原文

是否可以同时请求 1 个以上的 Feed?

例如

google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'1\'),get_it(\'http://rss.golem.de/rss.php?feed=RSS1.0\',\'99\')'});

或...

 google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'99\')'});
google.load("feeds", "1",{"callback" : 'get_it(\'http://rss.golem.de/
rss.php?feed=RSS1.0\',\'99\')'});

两种解决方案都有效,但我不确定,这是正确的吗 (干净)方式?

提前致谢! 彼得

is it possible to request more than 1 Feed at the same time?

for example

google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'1\'),get_it(\'http://rss.golem.de/rss.php?feed=RSS1.0\',\'99\')'});

or ...

 google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'99\')'});
google.load("feeds", "1",{"callback" : 'get_it(\'http://rss.golem.de/
rss.php?feed=RSS1.0\',\'99\')'});

Both solutions are working but i am not sure, is this the right
(clean) way?

Thanks in advance!
Peter

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

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

发布评论

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

评论(1

蒲公英的约定 2024-09-24 21:36:57

所以我认为你对正在发生的事情有点困惑。当您调用 google.load("feeds", "1",{"callback": "get_it('http://myfeed.com/whatever')"}) 时,您不是请求 Google 加载 http://myfeed.com/whatever 上的 Feed。你的意思是:“嘿,Google,加载 javascript 以支持您的 feed api,当您的 feed api 全部加载并准备好使用时,调用 get_it('http://myfeed.com/无论如何'),其中大概 get_it 是您已经在页面中定义的函数,它使用 Google 的 feed api 来完成其任务,

所以我认为通过定义可以更好地实现您的目的 。一个 javascript 函数来执行 feed 已准备好,类似于:

function feed_api_ready() {
  get_it('http://www.fernsehkritik.tv/?feed=podcast', '99');
  get_it('http://rss.golem.de/rss.php?feed=RSS1.0', '99');
}

然后简单地调用:

google.load("feeds", "1",{"callback" : 'feed_api_ready'})

当 Google API 全部加载时,这将立即执行两个“go get the feeds”函数

现在,至于获取 feed 。并行:无论您相信与否,Javascript 也不会真正具有任何阻止和等待网络 I/O 的能力,因此 JavaScript 中从网络获取内容的任何内容都必须编写。形式:“发出这个网络请求,当您最终得到响应时,将调用一个函数”,但与此同时,浏览器上的 JavaScript 引擎会继续运行,而不等待响应返回。

这意味着,在上面,您将触发对 http://www.fernsehkritik.tv/?feed=podcast 的请求,并且您的浏览器将继续执行 JavaScript,而无需等待网络响应,并且您将触发 http://rss.golem.de/rss.php?feed=RSS1.0 的第二个请求。因此,即使浏览器中的 javascript 不允许执行多线程,两个提要的网络流量也会并行返回到您的浏览器。

So I think you're a slight bit confused at to what's going on. When you call google.load("feeds", "1",{"callback": "get_it('http://myfeed.com/whatever')"}), you're not requesting that Google go load the feed at http://myfeed.com/whatever. What you're saying is: "Hey, Google, load up the javascript to support your feed api, and when your feed api is all loaded and ready to use, call get_it('http://myfeed.com/whatever'), where presumably get_it is a function you've defined already in your page that uses Google's feed api to do its thing.

So I think your purpose would be better served by defining a single javascript function to execute one the feed is ready, something like:

function feed_api_ready() {
  get_it('http://www.fernsehkritik.tv/?feed=podcast', '99');
  get_it('http://rss.golem.de/rss.php?feed=RSS1.0', '99');
}

And then calling simply:

google.load("feeds", "1",{"callback" : 'feed_api_ready'})

That'll execute both "go get the feeds" functions right away when the Google API is all loaded.

Now, as for getting the feeds in parallel: believe it or not, that will also load the feeds in parallel. Javascript doesn't really have any ability to block and wait on network I/O, so anything in javascript that gets stuff from the network always has to be written in the form: "Go make this network request, and here's a function to call when you eventually get a response". But in the meantime, the javascript engine on the browser keeps going without waiting for the response to come back.

This means that above, you'll fire off the request for http://www.fernsehkritik.tv/?feed=podcast and your browser will continue executing javascript without waiting for the network to respond, and you'll fire off the second request for http://rss.golem.de/rss.php?feed=RSS1.0. So the network traffic for both feeds will then be coming back to your browser in parallel, even though javascript in the browser doesn't allow multiple threads of execution.

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