header - Why put JavaScript in the footer of a page? -


so bought , downloaded template themeforest. set template on local server. generated navigation, has dropdown menus, codeigniter. had in menu coded correctly. had header generated , went test out , realized dropdown menus not working. spent 2 hours trying figure out wrong code. realized javascript files included in footer of template... had not yet generated.

so question is... why put javascript files in footer of html page? thought js supposed located in header of file. right?

there different ways load script file web page.

but loading scripts @ bottom of page have following advantages.

  1. will not block dom content loaded.
  2. all dom elements available scripts being loaded.
  3. if using third-party libraries such jquery, can skip $(document).ready(function () {...}); dom loaded.

hope helps.


Comments