Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
When is it better to declare a javascript file?
One way is to declare it upfront before the <body> tag, in the <head> section.
Another is to declare the source file right before you use any of the code in the src; right before the closing tag </body>.
Assuming that in both cases, you will ensure that your javascript code will only be executed after the page (document) has finished loading and is ready.
The best practice is to put javascript sources files before the closing body tag not to prevent the loading of the page. So, with js at the end of the html will allow to load the content (HTML & CSS) first and not to get waiting the user before display the entire page.