I am working with both amq.js (ActiveMQ) and Google Maps. I load my scripts in this order
Do you mean that AMQ depends on the Prototype library? I can't see an import for that library in the code you've provided.
Yes for ActiveMQ's javascript (amq.js) does depend on Prototype. In the amq.js it loads 3 scripts, _amq.js, behaviour.js and prototype.js.
Thanks you for your help on the JavaScript load order wrumsby. This tells me that my bug is in another castle :(
I guess I have a different problem. I also checked the js files from ActiveMQ 5.0 to 5.1 and noticed they were the same as well. Something has changed in 5.0 to 5.1 that requires a refresh for the topics to subscribe. I'll keep looking, but thanks for eliminating this possible cause.
I had a similar problem to this, only with a single script. The solution I came up with was to use addEventListener("load",fn,false)
to a script
object created using document.createElement('script')
Here is the final function which loads any standard JS file and lets you add a "post load" script.
function addJavaScript( js, onload ) {
var head, ref;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
script = document.createElement('script');
script.type = 'text/javascript';
script.src = js;
script.addEventListener( "load", onload, false );
head.appendChild(script);
}
I hope this may help someone in the future.
Is there a way to make sure both scripts load before I use them in my application.js?
JavaScript files should load sequentially and block so unless the scripts you are depending on are doing something unusual all you should need to do is load application.js after the other files.
Non-blocking JavaScript Downloads has some information about how scripts load (and discusses some techniques to subvert the blocking).
AMQ depends on prototype which the error console in FireFox says object is not defined.
Do you mean that AMQ depends on the Prototype library? I can't see an import for that library in the code you've provided.
cross-domain scripts are loaded after scripts of site itself, this is why you get errors. interestingly, nobody knows this here.
in jquery you can use:
$(document).ready(function(){/*do stuff here*/});
which makes sure the javascript is loaded and the dom is ready before doing your stuff.
in prototype it looks like this might work
document.observe("dom:loaded", function() {/*do stuff here*/});
If I understand your problem correctly.. I think that may help..
If you don't want to rely on a lib to do this... I think this might work:
<script>
function doIt() {/*do stuff here*/}
</script>
<body onLoad="doIt();"></body>