Firefox 不执行动态加载的

我正在使用脚本标签长轮询技术实现 Comet,基于 此页面。继我的上一个问题之后,我一切都正常,除了一个烦恼,这种烦恼只发生在 Firefox 中。

在初始页面加载时,我的 Comet 客户端 JavaScript 向 Comet 服务器发送两个请求(以动态生成的

  1. get_messages - 这是对来自应用程序的消息的持续轮询。
  2. initialise - 这是启动时的一次性请求。

这两者是同时发生的——也就是说,它们的

在 Firefox 3.5 中,在 initialise 请求的

为什么 Firefox 会这样做以及如何修复它?我想我可以尝试在服务器上通过在初始化响应的同时发送一条虚拟“消息”来解决这个问题,但这确实是一种黑客行为。如果可能的话,我想理解并正确解决这个问题。

I'm implementing Comet using the script tag long polling technique, based on this page. Following on from my previous question, I've got it all working, except for one annoyance, which only happens in Firefox.

On the initial page load my Comet client JavaScript sends two requests to the Comet server (in the form of dynamically generated <script> tags that are appended to the DOM):

  1. get_messages - this is ongoing poll for messages from the application.
  2. initialise - this is a once-off request at startup.

These two happen at the same time - that is, the <script> tags for both of them exist in the DOM at the same. (I can see them in the Firebug DOM inspector.) The server immediately sends some script as a response to the initialise request, but it doesn't send anything for the get_messages request until there's actually a message, which may take a while.

In Firefox 3.5 the script returned in the <script> tag for the initialise request does not get executed until the other <script> tag (for get_messages) also loads! In Chrome 3 and IE 8 this works fine - the script is executed as soon as it's received.

Why does Firefox do this and how do I fix it? I suppose I could try to work around it on the server by sending a dummy "message" at the same time as the initialise response, but that's quite a hack. I'd like to understand and fix this properly, if possible.

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

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

发布评论

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

评论(2

最偏执的依靠 2024-08-20 07:30:28

在我看来,这是一个加载顺序的问题。 Firefox 始终确保排队的请求按照请求的顺序执行。 IE 不能确保这一点(Chrome 不确定)。

无论如何,如果您不应该在初始化代码之后调用 get_messages,那么无论如何您都希望在初始化函数的回调中触发该请求。无论如何,您都希望这样做,因为其他浏览器也可能不一致。 IE6 在加载顺序方面肯定与其他浏览器的工作方式不同 - 在长轮询请求完成之前,它不会继续加载 DOM,因此您将不得不等待长轮询间隔只是为了查看主 DOM 加载。

如果您想了解详细信息,可以查看我们的 javascript 客户端的源代码,我们在构建 ASP.NET comet 服务器 WebSync 时遇到了类似的问题。可以在此处查看源代码:

http://sync.frozenmountain.com/client.ashx?debug=true

搜索“ie6”以查看一些解决方法。

Seems to me to be a question of load order. Firefox always ensures that requests queued up execute in the order in which they were requested. IE does NOT ensure this (not sure about Chrome).

Regardless, if you shouldn't be calling get_messages until after the initialize code, you would want to trigger that request in the callback from your initialize function anyway. You'd want to do this no matter what, because other browsers may be inconsistent as well. IE6 for sure doesn't work the same way as other browsers regarding load order - it won't continue loading the DOM until the long-poll request completes, so you'd be stuck waiting around for your long poll interval just to see the main DOM load.

You can check out the source for our javascript client if you want details, we ran into similar issues when building our ASP.NET comet server, WebSync. The source can be viewed here:

http://sync.frozenmountain.com/client.ashx?debug=true

Do a search for "ie6" to see some of the workarounds.

流星番茄 2024-08-20 07:30:28

我不确定为什么会发生这种情况,但也许一个简单的解决方法是在初始化请求完成后仅添加 get_messages

I'm not sure why this is occurring, but perhaps a simple workaround would be to only add the get_messages <script> tag once the initialise request has completed. (I presume you have some callback that processes the response from the initialise request.)

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