Put Your Javascripts At The Bottom

Most likely you’ve been taught to put your javascript <script> tags in the <head>. Well, according to the Yahoo! Exceptional Performance team, you shouldn’t. In fact, they advocate that you should place your javascript <script> tags at the very bottom of your document—just above the </body> closing tag.

If external javascript files are included in the <head>, the browser downloads those js files before rendering the rest of the page. Who wants to wait? If you include the scripts at the bottom of your document, the page loads up then fetches the scripts. In most cases, this is desirable.

Some cases you wouldn’t want to put javascript at the bottom:
  1. You’re loading up valuable page content with javascript.
  2. Some inline javascript relies on your external javascript files.
  3. Your boss told you to put them in the <head> tag.

Thanks to Robert Nyman for the reminder.

Responses

#1---update
#2--add my blog to your favorites.
  • avatar
  • mark
  • May 21, 10:01pm
i wondered about that. you're such a genius.

Respond