Including jQuery in HTML


After downloading or selecting a CDN, the next step is to include jQuery properly in the HTML file.

If jQuery is not included in the correct place, the code may not work as expected.

jQuery can be included in two common locations:

  • Inside the head section
  • Before the closing body tag

Both methods are used in real projects depending on the situation.

Including jQuery inside the head section loads the library before the page content.

However, this may slightly affect page loading speed if not handled properly.

Including jQuery before the closing body tag is the most recommended method.

It allows the page content to load first and improves performance.

Always load jQuery before your custom JavaScript file.

If custom code is loaded first, jQuery functions will not work.

Important Rules:

  • jQuery must load before custom scripts
  • Use body bottom placement for better speed
  • Keep scripts organized in js folder
  • Avoid loading jQuery multiple times