CSS blocking and JS blocking __js

Source: Internet
Author: User

JS blocking features: All browsers in the download JS, will prevent all other activities, such as other resources download, content rendering and so on. It is not until JS downloads, parses, and executes that it continues to download other resources in parallel and renders content. In order to improve the user experience, the next generation of browsers support the parallel download JS, but JS downloads will still block other resources download (for example, pictures, CSS files, etc.).

Because browsers need to rebuild the DOM tree in order to prevent JS from modifying the DOM tree, other downloads and rendering are blocked.

Embedding JS blocks the rendering of all content, and external JS only blocks the display of subsequent content, and 2 ways will block subsequent downloads of resources. That is, the external style does not block the loading of the external script, but it blocks the execution of the external script.

How can CSS block load. CSS can be downloaded in parallel, under what circumstances will be blocked load (in the test observation, IE6 under the CSS are blocked loading)

When the CSS followed by embedded JS, the CSS will be blocked after the download of resources. And when the embedded JS in front of the CSS, there will be no blocking situation.

Root cause: Because browsers maintain the order of CSS and JS in HTML, stylesheets must be loaded and parsed before the embedded JS is executed. and embedded JS will block the subsequent load of resources, so there will be the above CSS blocking downloads.

Embed JS should be placed in what position.

   1, put at the bottom, although put at the bottom will block all rendering, but will not block the resource download.

   2, if embedded in the head of JS, please embed JS in the CSS header.

   3, the use of defer (only support IE)

   4, do not embed in the JS to invoke a long run of functions, if you must use, you can use ' settimeout ' to call
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.