Prev: active (x)html newsgroup?
Next: Debt consolidation loan. Unsecured debt consolidation. Debt consolidation loans.
From: Nasser M. Abbasi on 3 Apr 2010 03:57 According to http://www.w3schools.com/js/js_whereto.asp it says: "Put your functions in the head section, this way they are all in one place, and they do not interfere with page content." But according to "High Performance JavaScript (Paperback) by Nicholas C. Zakas" http://www.amazon.com/High-Performance-JavaScript-Nicholas-Zakas/dp/059680279X/ref=sr_1_37?ie=UTF8&s=books&qid=1270279493&sr=1-37#reader_059680279X on page 3 it says: "it's recommended to place all <script>tags as close to the bottom of the <body> tage as possible" --Nasser
From: Hans-Georg Michna on 3 Apr 2010 06:27 On Sat, 3 Apr 2010 00:57:31 -0700, Nasser M. Abbasi wrote: >According to > >http://www.w3schools.com/js/js_whereto.asp > >it says: > >"Put your functions in the head section, this way they are all in one place, >and they do not interfere with page content." > >But according to > >"High Performance JavaScript (Paperback) by Nicholas C. Zakas" > >http://www.amazon.com/High-Performance-JavaScript-Nicholas-Zakas/dp/059680279X/ref=sr_1_37?ie=UTF8&s=books&qid=1270279493&sr=1-37#reader_059680279X > >on page 3 it says: > >"it's recommended to place all <script>tags as close to the bottom of the ><body> tage as possible" There is no very simple answer to this question. I'll try to make it short. Scripts in head are executed before the entire page is loaded. If you just want to load some functions that are later called through user actions, head is fine. If you want to execute some script after the page is fully loaded, the most reliable way in a head-loaded script is to let a function run when the window.onload event fires. However, that has the disadvantage that the script runs only after all parts of the page, particularly images, are loaded. If you want to execute some script after the page is fully loaded and the DOM complete, but still as early as possible, i.e. before all images are loaded, it is better (and just as standards-conformant) to put the script just before the </body> end tag. There are some tricks to make scripts in head start earlier, but none is very simple and works across different browsers. Hans-Georg
From: rf on 3 Apr 2010 06:38 "Hans-Georg Michna" <hans-georgNoEmailPlease(a)michna.com> wrote in message news:pk5er5h2qc4u325f8i8dfadft9d2vpd6pi(a)4ax.com... > On Sat, 3 Apr 2010 00:57:31 -0700, Nasser M. Abbasi wrote: > >>According to >> >>http://www.w3schools.com/js/js_whereto.asp In addition to what Hans-Georg has so admirally pointed out: Don't believe many of the things that W3schools says. The site is full of errors.
From: Garrett Smith on 3 Apr 2010 13:26 rf wrote: > "Hans-Georg Michna" <hans-georgNoEmailPlease(a)michna.com> wrote in message > news:pk5er5h2qc4u325f8i8dfadft9d2vpd6pi(a)4ax.com... >> On Sat, 3 Apr 2010 00:57:31 -0700, Nasser M. Abbasi wrote: >> >>> According to >>> >>> http://www.w3schools.com/js/js_whereto.asp > > In addition to what Hans-Georg has so admirally pointed out: Don't believe > many of the things that W3schools says. The site is full of errors. Obvious, glaring errors. THe FAQ used to contain w3schools links. THere was a long time nagging request to remove these links. I cannot recall any complaints when that request was fulfilled. -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/
From: David Mark on 3 Apr 2010 15:31
Nasser M. Abbasi wrote: > According to > > http://www.w3schools.com/js/js_whereto.asp > > it says: > > "Put your functions in the head section, this way they are all in one place, > and they do not interfere with page content." > > But according to > > "High Performance JavaScript (Paperback) by Nicholas C. Zakas" > > http://www.amazon.com/High-Performance-JavaScript-Nicholas-Zakas/dp/059680279X/ref=sr_1_37?ie=UTF8&s=books&qid=1270279493&sr=1-37#reader_059680279X > > on page 3 it says: > > "it's recommended to place all <script>tags as close to the bottom of the > <body> tage as possible" > > Both generalizations are wrong. :) |