« Return to Thread: Javascript at the end of a page

Javascript at the end of a page

by dear_stephen :: Rate this Message:

Reply to Author | View in Thread

Hi

I have been reading "High Performance Web Sites" from O'Reilly in which they state that putting javascripts at the top of your html page prevents the browser from rendering until the scripts are downloaded. This is illustrated at http://stevesouders.com/hpws/js-middle.php

Of course I can move them down the bottom in the layout, but then I can't add dependant scripts in a decorated page.

Example Decorated Page
      <html>
         <head>
              <meta name="layout" content="myLayout" />
         </head>
         <body>Page to be decorated
           <script src="thisPageSpecificScriptDependantOnGlobal.js"></script>
         </body>
      </html>


Example decorator layout:

      <html>
         <head>
              <g:layoutHead />
         </head>
         <body><g:layoutBody />
            <script src="global.js" />
         </body>
      </html>


This results in:
      <html>
         <head>
         </head>
         <body>Page to be decorated
           <script src="thisPageSpecificScriptDependantOnGlobal.js"></script>
           <script src="global.js" />
         </body>
      </html>


The problem is that the first script needs to be below the second script.

Does anyone have a possible solution?

Cheers,
Stephen

 « Return to Thread: Javascript at the end of a page