ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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
تم إضافة السؤال من قبل Ahmad Al-Mutawa , Lead Engineer, System Application , Saudi Iron & Steel Company (HADEED)
تاريخ النشر: 2016/12/12
Jonathan de Flaugergues
من قبل 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.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟