I am trying to make a javascript file which creates a openheatmap. I need to include two different javascript src files but what I am currently doing is not working, this is what I am doing now.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="http://static.openheatmap.com/scripts/jquery.openheatmap.js" type="text/javascript"></script>
Is there a better way to do this?
There is a better way to include JavaScript files - you do it late in your file, especially where the script is not hosted by you. This allows the page to load without being blocked loading external resources.
So I would recommend you put all scripts just before the closing body
tag.
You can even take this a stage further and load the scripts without blocking the page rendering, which you can do with the defer attribute (which unlike the async attribute guarantees the order of execution, which looks important in your example).
<script defer src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script defer src="http://static.openheatmap.com/scripts/jquery.openheatmap.js"></script>
<script defer>
// JavaScript here...
</script>
</body>
You can also use an onload attribute with the defer attribute to specify a method to run once the DOM is ready.
<script defer onload="MyStuff.domLoaded();">
For the other part of your question, regarding whether your script works, please supply some more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With