javascript - Where do I put the jQuery script tag? -


in documentation see jquery script tag beneath <title> in head, when go other sites (the initializr template first off top of head), drop bottom of body (you know, right before </body>).

which of these 2 right?

quoting ydn best practices speeding web site:

put scripts @ bottom

the problem caused scripts block parallel downloads. http/1.1 specification suggests browsers download no more 2 components in parallel per hostname. if serve images multiple hostnames, can more 2 downloads occur in parallel. while script downloading, however, browser won't start other downloads, on different hostnames.

in situations it's not easy move scripts bottom. if, example, script uses document.write insert part of page's content, can't moved lower in page. there might scoping issues. in many cases, there ways workaround these situations.

an alternative suggestion comes use deferred scripts. defer attribute indicates script not contain document.write, , clue browsers can continue rendering. unfortunately, firefox doesn't support defer attribute. in internet explorer, script may deferred, not as desired. if script can deferred, can moved bottom of page. make web pages load faster.

it's funny people used i should slapped upside head doing that when i said in 2009 , it's best practice... progress.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -