When do you choose to load your javascript at the bottom of the page instead of the top?

后端 未结 9 1217
渐次进展
渐次进展 2020-12-10 17:15

I have seen JavaScript libraries being loaded at the top and bottom of the page.

I would love to know when to make these choices. All the JavaScript code I\'ve writt

9条回答
  •  我在风中等你
    2020-12-10 17:48

    Because of the fact that browsers have to pause displaying content of a page when it's parsing a Javascript file, the recommendation is to load the Javascript at the bottom of the page to speed up displaying a page's content. This works best if your website can be rendered without any Javascript executing to modify the page because the page will be available for user interaction even if a script hangs for longer than expected.

提交回复
热议问题