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):
get_messages
- this is ongoing poll for messages from the application.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.