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

前端 未结 8 1081
清酒与你
清酒与你 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

    So I know this is an old discussion, but I've been reading about this topic and reading other answers on StackOverflow...

    It actually doesn't matter where you put the jQuery tag anymore:

    Finally, a word about persistent folklore. You may have encountered the frequently repeated advice to “always place JavaScript at the bottom of the page just before the closing tag”. This was once true because web browsers loaded scripts sequentially and blocked loading and rendering until each script was complete. This is no longer true; modern browsers do “preload scanning” and begin loading all scripts in parallel, whether listed in the head element or at the bottom of the page. External JavaScript often is loaded asynchronously and is written so it won’t execute until the page is loaded and the DOM is ready. Loading a script in the head element is no longer a bad practice.

    http://railsapps.github.io/rails-javascript-include-external.html

提交回复
热议问题