Results 1 to 2 of 2

Thread: Sharing an Optimization Tip

  1. #1
    Join Date
    Dec 2009
    Location
    San Diego, California
    Posts
    161

    Post Sharing an Optimization Tip

    The following code is placed before the closing body tag (and not in the head, as is traditionally done).

    Code:
    <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/java...script-better/ if interested.)

    Hope this helps someone else as much as it helped me.

    Cheers

  2. #2
    Join Date
    Aug 2009
    Location
    Lutterworth, Leicester
    Posts
    161
    Nice advice,

    I've not yet had the chance to test this, but am certainly keen to. Google is really focusing on page load time and quality, and this will continue to develop in importance.

    I imagine this stems from, in my opinion, the under performance of internet from mobile devices, well certainly in the UK. Over 3G, my iPhone still seems to take an age to load heavy pages.

    Michael.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •