Thread: JS fundamentals
View Single Post
Old 09-25-2012, 07:04 PM   PM User | #41
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,553
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by zygezund View Post
My question, actually, was, why not in the <HEAD>, where they could peacefully sleep, until called?
I think the <head> section was included into HTML mostly for that purpose (to keep executable code sleeping) otherwise I do not see any big reason, rather then decorative, to have this special section of HTML.
because they don't sleep, they bring the page-load process to a halt as soon as they are encountered. it's better to have that pause happen after the user can see and click the styled html than before they can see anything. for CSS, the opposite it true; you don't want to see any html before it's styled, else you get the much loathed flash of styled content. the better experience is had by waiting for the css.

of course these are just entry-level guidelines, you need to experiment with different placements and techniques according to your site and audience.

look at google for example, and see if you can tell why it's source is like that. they have a huge script block inline, in the head.

of the 100kb, only 10kb is actually HTML, the rest is js and css. some of the css is in the body, and some in the head. they also deliver CSS as json called from an external script tag lading in the middle of the body!

It's not based on theory, it's based on billions of observations about what works best. Since the navigation timing API came out, chrome's gotten even faster, go figure. so take anything you read or hear with a grain of salt, numbers talk louder than theory.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
zygezund (09-26-2012)