Why prefer to put JavaScript in the footer of an HTML page?

JavascriptWeb DevelopmentFront End Technology

With JavaScript, you can put JavaScript anywhere on the page, whether inside <head> or <body> tag. But, it is a good practice to add JavaScript in the footer i.e. just before closing the <body> tag. This is because −

  • It loads script faster.
  • It will not block any DOM content to load.
  • It loads the web page before loading JavaScript
  • Improves display speed
  • Page loads faster
Updated on 13-Jun-2020 06:13:45