On Feb 7, 2008 12:00 PM, Rahmin Pavlovic <[EMAIL PROTECTED]> wrote: > > Michael B Allen wrote: > > > Is it considered bad practice to emit scripts within the body of a > > page such as immediately preceeding the form that uses it? It seems to > > work fine but from looking at some random sites I have yet to see an > > example of this. Logically it makes sense to put the JavaScript close > > to where it will be used no? > > > > That actually makes perfect sense in terms of download speed. It became > somewhat of a standard practice to include JS in the HEAD of the document, > but that actually slows things down. > > I actually wrote about this and a bunch of other JS optimization tricks in > my well-ignored Wordpress blog (primarily ignored by me): > http://insite-out.com/#load-scripts-last
Insightful post, although I disagree with the bit about destructors. I prefer to let the scope+garbage collection destroy objects rather than doing it manually. The key thing to understand is that the browser stops rendering the page when it encounters a <script> tag. The script is fully parsed and executed, before rendering resumes. Browsers must work this way because the script may contain "document.write". Presently, the defer attribute is not supported across all browsers thus it is not a viable workaround. -John C. _______________________________________________ New York PHP Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk NYPHPCon 2006 Presentations Online http://www.nyphpcon.com Show Your Participation in New York PHP http://www.nyphp.org/show_participation.php