Does the [removed] tag position in HTML affects performance of the webpage?

前端 未结 8 1094
清酒与你
清酒与你 2020-11-29 19:39

If the script tag is above or below the body in a HTML page, does it matter for the performance of a website?

And what if used in between like this:

         


        
8条回答
  •  囚心锁ツ
    2020-11-29 20:26

    Along with the Performance aspect, you also need to be careful whenever you include the

    The content of the document......

    Here, notice that the script is loaded before the DOM (or the

    tag) is loaded, which causes a failure in the script (Since the getElementById cant find the element with name 'demo').

    In such cases you have to use the script within the body tag only.

    Considering the other answers, its better to have the script always before the tag as you never know whether the scripts that you would load externally have any such dependencies on your DOM.

    Reference: Detailed problem description

提交回复
热议问题