Web optimization-style sheets, scripts

Source: Internet
Author: User

To avoid white screen, place the style sheet in the head at the top of the document. There are two ways to include a style sheet in a document: using the link tag and the @improt rule. A stryle block can contain multiple @import rules, but @import rules must be placed before all other rules. @import rule causes the component to be unordered when it is downloaded.

"If the style sheet is still loading, building the rendering tree is a waste because there is no need to return anything until all the stylesheets have been loaded and disassembled." Otherwise, displaying content before it is ready encounters the flash of unstyled content issue. ”

The biggest impact on response time is the number of components in the page. The http1.1 specification, which recommends that browsers download two components in parallel from each host name. If a Web page evenly places components under two hosts, the overall response time can be reduced by about half. Instead of relying on users to modify browser settings, front-end engineers simply use the CNAME to place components in multiple host names.

The advantages of parallel download components are obvious. Then, when the script is downloaded, the parallel download is actually disabled (even if a different host name is used, the browser does not start another download.) One reason is that the script might use document.write to modify the contents of the page, so the browser waits to ensure that the page is properly laid out. Another reason is to ensure that the scripts are executed in the correct order. Because dependencies exist between them, it can cause JavaScript errors if they are not executed sequentially.

Obfuscation is another optimization method that can be applied to the source code. As with refiners, it overflows annotations and whitespace, and it also overwrites the code. The most rewritten part, the names of functions and variables will be converted to shorter strings, where the code is more refined and harder to read. Thin tools can use jsmin.

  

  

The above content is excerpt from "High-performance website Construction Guide"

Web optimization-style sheets, scripts

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.