Js distal placement difference

js can be divided into the external and internal.

Internal js

Internal js also known as JS script this page,
inside the js generally placed within the body, the purpose of doing so are many,

  1. Do not block the page loads (js are cached in fact);
  2. Can operate directly in the js dom, the dom is ready at this time, which is to ensure js runtime dom is there.
  3. 'Owl Book' recommendation is on the way to the bottom of the page, or listening readystate window.onload to trigger js

External js

Js generally placed outside the head

js in the head will block the rendering of pages and page transmission.

JavaScript needs to be performed within the head end began to render body, so try not to JS files placed in the head. After the completion may be selected document, and performing the introduction of particular block or JavaScript.

The CSS should be written on the head in order to avoid missing page elements due to the style of the moment caused by the white pages or to the user a sense of flicker.


So js in head first after the implementation of the general, began to render the body page. In order to avoid the introduction of head js script blocking the main street is parsing engine for parsing dom, the dom rendering, the general principle is that the style in front, dom document, script last. Follow to parse the script and then render then execute that order.

Published 70 original articles · won praise 18 · views 50000 +

Guess you like

Origin blog.csdn.net/qq_40325734/article/details/102674685