What difference does it make to use several script blocks on a web page?

Posted by Jan Aagaard on Stack Overflow See other posts from Stack Overflow or by Jan Aagaard
Published on 2010-06-06T21:16:54Z Indexed on 2010/06/06 21:22 UTC
Read the original article Hit count: 266

Filed under:

What difference does it make to use more than one script block on a web page? I have pasted in the standard code for including Google Analytics as an example, and I have seen the same pattern used in other places. Why is this code separated into two separate script blocks instead of just using a single one?

<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
    try{
        var pageTracker = _gat._getTracker("UA-xxxxxx-x");
        pageTracker._trackPageview();
    } catch(err) {}
</script>

© Stack Overflow or respective owner

Related posts about JavaScript