Blaze: But how do you ensure that the JavaScript that you loaded with your trick then actually gets run? Call a function in that code that you know must exist?
One problem with this is that the loading (assignment to the src) will be *synchronous*. So if there is any hangup in getting the response from the server, the HTML page will be "dead"...no other JS code can run, events, can't happen, etc.
That's why people prefer using AJAX. The first A there means "Asynchronous". So while the loading from the server is taking place, all other code on the page is accessible. The completion of the load triggers the
onreadystatechange event. If the load hangs, the page keeps running.
A variation on your trick might be this:
Code:
<iframe style="display: none;" id="loadarea"></iframe>
<script type="text/javascript">
window.setInterval("document.getElementById('loadarea').src = 'http://www.mysite.com/update.js?nocash=' + Math.random()*500;",60000);
</script>
*NOW* the load *IS* asynchronous, by definition. And the code in the iframe can automatically start running itself, rather than waiting for a call from the parent. And, of course, the code in the iframe can refer to anything in the parent via
parent.someFunction() or similar.