Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8071705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:46:27+00:00 2026-06-05T13:46:27+00:00

This question is just to clear some things up. Some things like this have

  • 0

This question is just to clear some things up. Some things like this have been asked before, and this rounds them all up into one question – where should JavaScript go in the HTML document, or, more importantly, does it matter? So, one of the things I’m asking is, does

<head>
<script type="text/javascript">
alert("Hello world!");
</script>
</head>

at all differ (in terms of functionality) from

<body>
<!-- Code goes here -->
<script type="text/javascript">
alert("Hello world!");
</script>
</body>

More importantly, I want to focus on JS that modifies or uses elements from the DOM in any way. So I know that if you put something like document.getElementById("test").innerHTML = "Hello world!" before <element id="test"></element> in your body, then it won’t work since the body is loaded from top to bottom, making the JS load first, which will then proceed to try to manipulate an element that doesn’t exist yet. So it should, just like the above, either go in the <head> or just before the </body> tag. The question is, aside from organisation and sorting, does it matter which one of these is chosen, and if so, in what way?

Of course, there is also a third method – the jQuery way:

$(document).ready(function(){ /*Code goes here*/ });

That way, it doesn’t matter where in the body you place the code, since it will only be executed when everything has loaded. The question here is, is it worth importing a huge JS library just to use a method the need for which could be replaced with an accurate placing of your scripts? I’d just like to clear things up a little here, if you would like to answer, go ahead! Summary: where should different kinds of scripts go – head or body, and/or does it matter? Is jQuery worth it just for the ready event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:46:28+00:00Added an answer on June 5, 2026 at 1:46 pm

    Most recommended method is to put it before </body> tag. Yahoo performance article also suggests that other than YSlow and Page Speed addons by Yahoo and Google respectively.

    Quoting from Yahoo article linked above:

    The problem caused by scripts is that they block parallel downloads.
    The HTTP/1.1 specification suggests that browsers download no more
    than two components in parallel per hostname.
    If you serve your images
    from multiple hostnames, you can get more than two downloads to occur
    in parallel. While a script is downloading, however, the browser won’t
    start any other downloads, even on different hostnames.

    When you put scripts in <head> tag, the browsers goes for them thereby keeping other stuff on hold until scripts are loaded which users will perceive like slow loading of the page. This is why you should put scripts at the bottom.

    As for:

    $(document).ready(function(){/*Code goes here*/});
    

    It is fired when DOM is available and ready to be manipulated. If you put your code at the end, you won’t necessarily need this but usually this is needed because you want to do something as soon as DOM is available for use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this question might have been asked like 100 times, but, believe
I have just asked this question an hour ago but with regards to IE8
Forgive me if this has been asked before, I'm just unable to find an
First, I know this question has been asked several times before and that in
Just wanted a clear answer for a direct question -- google results have been
This question is just for a sake of knowledge. I don't have any practical
I know this question has been asked a couple of times, but there's something
I'm just starting out with Paypal, so this is a newbie question. I've been
Please do not mark it as a dupe of this question just yet: Bold
This question is just out of interest, and perhaps could be useful for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.