just a quick question concerning order of processing and the way DOM’s are processed.
My understanding is that it is best practice to include all JQuery scripts just before the tag. In my situation, I have a div container that witholds most of my body elements. Among these elements are my footer, which has the company name and year. Currently my pages are setup in a modular fashion (header.php, page.php, footer.php) and I want to include my company name and year in the footer.php, as this would obviously allow for easy editing of the company name. My problem lies in wanting to maintain the format of keeping jquery scripts just before the body. With this layout, I cannot include the company name in my footer.php without including the jquery scripts within my div. I’ll show you what I mean with psuedocode:
How it’s currently setup:
page.php
<body>
<div class="container">
//body elements
<hr>
<p>© Company 2012</p>
</div>
<script>
//some javascript #1
</script>
<script>
//some javascript #2
</script>
footer.php:
<script> //same static javascript that doesn't change page to page </script>
</body>
How I want to set it up (allows for easy site-wide changing of company name):
page.php
<body>
<div class="container">
//body elements
<script>
//some javascript #1
</script>
<script>
//some javascript #2
</script>
footer.php:
<hr>
<p>© Company 2012</p>
</div>
<script> //same static javascript that doesn't change page to page </script>
</body>
I realize I can do it this way, but I am afraid of losing optimization since my jquery scripts will technically be executing within the container.
With all of this said, will including my jquery scripts before the closing div of the page’s container, but after all the contents of the div, cause it to be less efficient than if it was after said div closing?
I realize all of this entirely depends on how a DOM is processed, but I can’t seem to find any information on whether or not the DOM processes as it goes, or if it requires an ending tag before it’s actually processed, which would in turn cause the second method to be slower.
Let me know if I can clear anything up.
Thanks
Inline scripts block the rendering of the whole page. (Only Opera does some rendering) So it doesn’t matter where you put them in your case. In general it’s better to put them at the end because external files can still be downloaded, and if flushing is enabled something can be rendered.
External scripts only block the rendering of everything below them.