I want to use Head JS to dynamically load all of the other scripts for my pages. I'm planning on using the version hosted by CDNJS to take advantage of the better caching, decreased latency, etc.
I have no reason to think CDNJS is going anywhere, but even for Google CDN hosted files like jQuery, I like to include a fallback. When I'm using jQuery though, the files are included at the end of the <body>
tag. Due to the nature of Head JS, I need to include it in the <head>
of my page.
In the <body>
I would use two lines like this:
<script src="http://cdnjs.cloudflare.com/ajax/libs/headjs/0.96/head.min.js"></script>
<script> window.head || document.write('<script src="js/libs/head-0.96.min.js"><\/script>') </script>
Can I use this same set of lines in the head as a fallback? Won't document.write()
overwrite my entire page? Don't scripts load differently when they exist in the <head>
due to the order that browsers parse the DOM?
I'm still pretty new to this, so any guidance would be hugely helpful! Thanks!