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

后端 未结 9 1228
渐次进展
渐次进展 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:55

    I place all CSS in the HEAD to avoid excessive screen paintings and flashes of style.

    I place most JavaScript file requests at the bottom of the page so that the page can render quickly (HTML/CSS loading will block until script tags above them have been loaded and processed). Any code that needs to be executed after the library files have loaded are executed onDOMReady, which is all code except for library initialization. I pretty much followed Google's PageSpeed recommendations.

    I've been thinking about using LABjs as well to further decrease page load times, but this works well enough right now.

提交回复
热议问题