Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"JavaScript placed at the end of the document so the pages load faster" TRUE? [duplicate]

Possible Duplicate:
Javascript on the bottom of the page?

I saw a comment in some twitter bootstrap example. It says

JavaScript placed at the end of the document so the pages load faster

Is this true?? If yes then How it works??

like image 750
vs4vijay Avatar asked Jan 27 '13 11:01

vs4vijay


1 Answers

There are a number of advantages

  • There’s no need to have a check if the DOM is loaded, since by having the scripts at the end, you know for sure it is.
  • A JavaScript script file has to be loaded completely before a web browser even begins on the next JavaScript file. The effect of this, if the JavaScript files are included at the top of the document, is that it will be a visual delay before the end user sees the actual page. This is completely avoided if you include the JavaScript files at the end of the document.

There are some limitations as well

While including the JavaScript files at the bottom helps us around the problem of delaying the page rendering, thus giving the impression that each page in the web site loads faster, it does have a drawback.

  • If the page is visible to the end user, but the JavaScript files haven’t finished loading yet, no events have been applied to the elements yet (because everyone uses an unobtrusive approach, right?) and the user might start clicking around and not getting the expected results.

  • If you have proper fallbacks, e.g. a link element which gets content via AJAX if JavaScript is supported and the proper event has been applied, otherwise it’s a normal link leading to another page, then the problem isn’t that bad. Still somewhat annoying, though.

Useful Article Here

like image 155
Muhammad Hani Avatar answered Nov 15 '22 17:11

Muhammad Hani