Where will the CSS block, and where the JS block will appear?

Source: Internet
Author: User

jBlocking characteristics of S:

All browsers in the download JS, will block all other activities, such as the download of other resources, content rendering and so on.

Until JS downloads, parses, executes, and then continues to download additional resources and render the content in parallel.

In order to improve the user experience, the next generation of browsers support parallel download js, but JS download will still block the download of other resources (such as. Pictures, CSS files, etc.).

* Because the browser needs to rebuild the DOM tree in order to prevent JS from changing the DOM tree, other downloads and renders are blocked.

* Embedded JS will block the rendering of all content, while external JS will only block the display of subsequent content, 2 ways will block the subsequent download of resources.

This means that external styles do not block the loading of external scripts, but they block the execution of external scripts.

How does a CSS block load?

CSS can be downloaded in parallel, under what circumstances will be blocked loading (in the test observation, IE6 under the CSS is blocked loading)

* When the CSS is followed by the embedded JS, the CSS will appear blocking the download of the resources behind the situation;

* And when embedding JS in front of the CSS, there will be no blocking situation.

Root cause:

* Because the browser will maintain the HTML in the order of CSS and JS, the stylesheet must be embedded in the JS before the execution of the load, parse out.

* While Embedded JS will block the subsequent loading of resources, so there will be the above CSS blocking download situation.

Where should embed JS be placed?

1, at the bottom, although placed at the bottom will still block all rendering, but will not block the download of resources.

2, if embedded JS placed in the head, please put embedded JS in the CSS head.

3. Using defer (ie only)

4, do not in the embedded JS call long-running function, if must be used, you can use ' setTimeout ' to invoke

Where will the CSS block, and where the JS block will appear?

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.