Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

When is it best to declare javascript SRC file, at the top of HTML or before the closing /body tag? and why?

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.

user-image
Question ajoutée par Ahmad Al-Mutawa , Lead Engineer, System Application , Saudi Iron & Steel Company (HADEED)
Date de publication: 2016/12/12
Jonathan de Flaugergues
par Jonathan de Flaugergues , software engineer , Abbeal

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.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?