TheMichael
21 Jul 2010, 12:03 AM
The following code is placed before the closing body tag (and not in the head, as is traditionally done).
<script type="text/javascript">
var DocumentHead = document.getElementsByTagName('head')[0];
function jsOptimizedLoader(src) {
var Script = document.createElement('script');
Script.src = src;
Script.type = 'text/javascript';
DocumentHead.appendChild(Script);
}
jsOptimizedLoader('js/foo.js');
jsOptimizedLoader('js/bar.js');
jsOptimizedLoader('js/etc.js');
</script>
Once your DOM has finished loading, all the scripts tags are added to the head via javascript. Allowing your page to display PRIOR to spending the time loading all of those scripts will win you usability points and ease of access points with your audience.
(You can find the more complete article in my blog at http://www.michaelhartmayer.com/javascript/loading-javascript-better/ if interested.)
Hope this helps someone else as much as it helped me.
Cheers
<script type="text/javascript">
var DocumentHead = document.getElementsByTagName('head')[0];
function jsOptimizedLoader(src) {
var Script = document.createElement('script');
Script.src = src;
Script.type = 'text/javascript';
DocumentHead.appendChild(Script);
}
jsOptimizedLoader('js/foo.js');
jsOptimizedLoader('js/bar.js');
jsOptimizedLoader('js/etc.js');
</script>
Once your DOM has finished loading, all the scripts tags are added to the head via javascript. Allowing your page to display PRIOR to spending the time loading all of those scripts will win you usability points and ease of access points with your audience.
(You can find the more complete article in my blog at http://www.michaelhartmayer.com/javascript/loading-javascript-better/ if interested.)
Hope this helps someone else as much as it helped me.
Cheers