Inclusion of JS in the head or immediately after opening the body tag

What is the difference between enabling Javascript in <head>and not immediately after the OPENING tag <body>?

Facebook Like a widget, this is one example where they offer to place the code immediately after opening the tag <body>. SiteCatalyst also offers this for its analytics code.

Despite the obvious difference between the inclusion of code in the element <head>, and not on the right before the closing tag </body>, I’m not sure what the difference is between <head>and immediately after opening the tag <body>.

+5
source share
2 answers

JavaScript - DOM ( HTML), JavaScript <body>, , <body> </body>.

, , DOM, </body>, , DOM. , DOM, HTML DOM (, <input> - ).

+6

script, script . , a script, . . - ( Google Analytics):

(function() {
        var ga = document.createElement('script');
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ('https:' == document.location.protocol 
          ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(ga, s);
    })();
0

All Articles